Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(664)

Side by Side Diff: src/client/mac/handler/minidump_generator.cc

Issue 136001: More code clean up (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: Created 14 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // If opening was successful, create the header, directory, and call each 187 // If opening was successful, create the header, directory, and call each
188 // writer. The destructor for the TypedMDRVAs will cause the data to be 188 // writer. The destructor for the TypedMDRVAs will cause the data to be
189 // flushed. The destructor for the MinidumpFileWriter will close the file. 189 // flushed. The destructor for the MinidumpFileWriter will close the file.
190 if (writer_.Open(path)) { 190 if (writer_.Open(path)) {
191 TypedMDRVA<MDRawHeader> header(&writer_); 191 TypedMDRVA<MDRawHeader> header(&writer_);
192 TypedMDRVA<MDRawDirectory> dir(&writer_); 192 TypedMDRVA<MDRawDirectory> dir(&writer_);
193 193
194 if (!header.Allocate()) 194 if (!header.Allocate())
195 return false; 195 return false;
196 196
197 int writer_count = sizeof(writers) / sizeof(writers[0]); 197 int writer_count = static_cast<int>(sizeof(writers) / sizeof(writers[0]));
198 198
199 // If we don't have exception information, don't write out the 199 // If we don't have exception information, don't write out the
200 // exception stream 200 // exception stream
201 if (!exception_thread_ && !exception_type_) 201 if (!exception_thread_ && !exception_type_)
202 --writer_count; 202 --writer_count;
203 203
204 // Add space for all writers 204 // Add space for all writers
205 if (!dir.AllocateArray(writer_count)) 205 if (!dir.AllocateArray(writer_count))
206 return false; 206 return false;
207 207
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 if (!context.Allocate()) 352 if (!context.Allocate())
353 return false; 353 return false;
354 354
355 *register_location = context.location(); 355 *register_location = context.location();
356 MinidumpContext *context_ptr = context.get(); 356 MinidumpContext *context_ptr = context.get();
357 context_ptr->context_flags = MD_CONTEXT_PPC_BASE; 357 context_ptr->context_flags = MD_CONTEXT_PPC_BASE;
358 358
359 #define AddReg(a) context_ptr->a = REGISTER_FROM_THREADSTATE(machine_state, a) 359 #define AddReg(a) context_ptr->a = REGISTER_FROM_THREADSTATE(machine_state, a)
360 #define AddGPR(a) context_ptr->gpr[a] = REGISTER_FROM_THREADSTATE(machine_state, r ## a) 360 #define AddGPR(a) context_ptr->gpr[a] = REGISTER_FROM_THREADSTATE(machine_state, r ## a)
361 361
362 AddReg(srr0); 362 AddReg(srr0);
363 AddReg(cr); 363 AddReg(cr);
364 AddReg(xer); 364 AddReg(xer);
365 AddReg(ctr); 365 AddReg(ctr);
366 AddReg(lr); 366 AddReg(lr);
367 AddReg(vrsave); 367 AddReg(vrsave);
368 368
369 AddGPR(0); 369 AddGPR(0);
370 AddGPR(1); 370 AddGPR(1);
371 AddGPR(2); 371 AddGPR(2);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 #endif 498 #endif
499 #undef AddReg(a) 499 #undef AddReg(a)
500 500
501 return true; 501 return true;
502 } 502 }
503 #endif 503 #endif
504 504
505 bool MinidumpGenerator::WriteThreadStream(mach_port_t thread_id, 505 bool MinidumpGenerator::WriteThreadStream(mach_port_t thread_id,
506 MDRawThread *thread) { 506 MDRawThread *thread) {
507 breakpad_thread_state_data_t state; 507 breakpad_thread_state_data_t state;
508 mach_msg_type_number_t state_count = sizeof(state); 508 mach_msg_type_number_t state_count
509 = static_cast<mach_msg_type_number_t>(sizeof(state));
509 510
510 if (thread_get_state(thread_id, BREAKPAD_MACHINE_THREAD_STATE, 511 if (thread_get_state(thread_id, BREAKPAD_MACHINE_THREAD_STATE,
511 state, &state_count) == 512 state, &state_count) ==
512 KERN_SUCCESS) { 513 KERN_SUCCESS) {
513 if (!WriteStack(state, &thread->stack)) 514 if (!WriteStack(state, &thread->stack))
514 return false; 515 return false;
515 516
516 if (!WriteContext(state, &thread->thread_context)) 517 if (!WriteContext(state, &thread->thread_context))
517 return false; 518 return false;
518 519
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 exception_stream->location = exception.location(); 574 exception_stream->location = exception.location();
574 MDRawExceptionStream *exception_ptr = exception.get(); 575 MDRawExceptionStream *exception_ptr = exception.get();
575 exception_ptr->thread_id = exception_thread_; 576 exception_ptr->thread_id = exception_thread_;
576 577
577 // This naming is confusing, but it is the proper translation from 578 // This naming is confusing, but it is the proper translation from
578 // mach naming to minidump naming. 579 // mach naming to minidump naming.
579 exception_ptr->exception_record.exception_code = exception_type_; 580 exception_ptr->exception_record.exception_code = exception_type_;
580 exception_ptr->exception_record.exception_flags = exception_code_; 581 exception_ptr->exception_record.exception_flags = exception_code_;
581 582
582 breakpad_thread_state_data_t state; 583 breakpad_thread_state_data_t state;
583 mach_msg_type_number_t stateCount = sizeof(state); 584 mach_msg_type_number_t stateCount
585 = static_cast<mach_msg_type_number_t>(sizeof(state));
584 586
585 if (thread_get_state(exception_thread_, 587 if (thread_get_state(exception_thread_,
586 BREAKPAD_MACHINE_THREAD_STATE, 588 BREAKPAD_MACHINE_THREAD_STATE,
587 state, 589 state,
588 &stateCount) != KERN_SUCCESS) 590 &stateCount) != KERN_SUCCESS)
589 return false; 591 return false;
590 592
591 if (!WriteContext(state, &exception_ptr->thread_context)) 593 if (!WriteContext(state, &exception_ptr->thread_context))
592 return false; 594 return false;
593 595
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 bool MinidumpGenerator::WriteMiscInfoStream(MDRawDirectory *misc_info_stream) { 929 bool MinidumpGenerator::WriteMiscInfoStream(MDRawDirectory *misc_info_stream) {
928 TypedMDRVA<MDRawMiscInfo> info(&writer_); 930 TypedMDRVA<MDRawMiscInfo> info(&writer_);
929 931
930 if (!info.Allocate()) 932 if (!info.Allocate())
931 return false; 933 return false;
932 934
933 misc_info_stream->stream_type = MD_MISC_INFO_STREAM; 935 misc_info_stream->stream_type = MD_MISC_INFO_STREAM;
934 misc_info_stream->location = info.location(); 936 misc_info_stream->location = info.location();
935 937
936 MDRawMiscInfo *info_ptr = info.get(); 938 MDRawMiscInfo *info_ptr = info.get();
937 info_ptr->size_of_info = sizeof(MDRawMiscInfo); 939 info_ptr->size_of_info = static_cast<u_int32_t>(sizeof(MDRawMiscInfo));
938 info_ptr->flags1 = MD_MISCINFO_FLAGS1_PROCESS_ID | 940 info_ptr->flags1 = MD_MISCINFO_FLAGS1_PROCESS_ID |
939 MD_MISCINFO_FLAGS1_PROCESS_TIMES | 941 MD_MISCINFO_FLAGS1_PROCESS_TIMES |
940 MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO; 942 MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO;
941 943
942 // Process ID 944 // Process ID
943 info_ptr->process_id = getpid(); 945 info_ptr->process_id = getpid();
944 946
945 // Times 947 // Times
946 struct rusage usage; 948 struct rusage usage;
947 if (getrusage(RUSAGE_SELF, &usage) != -1) { 949 if (getrusage(RUSAGE_SELF, &usage) != -1) {
948 // Omit the fractional time since the MDRawMiscInfo only wants seconds 950 // Omit the fractional time since the MDRawMiscInfo only wants seconds
949 info_ptr->process_user_time = 951 info_ptr->process_user_time =
950 static_cast<u_int32_t>(usage.ru_utime.tv_sec); 952 static_cast<u_int32_t>(usage.ru_utime.tv_sec);
951 info_ptr->process_kernel_time = 953 info_ptr->process_kernel_time =
952 static_cast<u_int32_t>(usage.ru_stime.tv_sec); 954 static_cast<u_int32_t>(usage.ru_stime.tv_sec);
953 } 955 }
954 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, info_ptr->process_id }; 956 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, info_ptr->process_id };
957 u_int mibsize = static_cast<u_int>(sizeof(mib) / sizeof(mib[0]));
Mark Mentovai 2010/07/28 18:20:42 I was surprised to see you using u_int instead of
955 size_t size; 958 size_t size;
956 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &size, NULL, 0)) { 959 if (!sysctl(mib, mibsize, NULL, &size, NULL, 0)) {
957 mach_vm_address_t addr; 960 mach_vm_address_t addr;
958 if (mach_vm_allocate(mach_task_self(), 961 if (mach_vm_allocate(mach_task_self(),
959 &addr, 962 &addr,
960 size, 963 size,
961 true) == KERN_SUCCESS) { 964 true) == KERN_SUCCESS) {
962 struct kinfo_proc *proc = (struct kinfo_proc *)addr; 965 struct kinfo_proc *proc = (struct kinfo_proc *)addr;
963 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), proc, &size, NULL, 0)) 966 if (!sysctl(mib, mibsize, proc, &size, NULL, 0))
964 info_ptr->process_create_time = 967 info_ptr->process_create_time =
965 static_cast<u_int32_t>(proc->kp_proc.p_starttime.tv_sec); 968 static_cast<u_int32_t>(proc->kp_proc.p_starttime.tv_sec);
966 mach_vm_deallocate(mach_task_self(), addr, size); 969 mach_vm_deallocate(mach_task_self(), addr, size);
967 } 970 }
968 } 971 }
969 972
970 // Speed 973 // Speed
971 uint64_t speed; 974 uint64_t speed;
972 const uint64_t kOneMillion = 1000 * 1000; 975 const uint64_t kOneMillion = 1000 * 1000;
973 size = sizeof(speed); 976 size = sizeof(speed);
(...skipping 26 matching lines...) Expand all
1000 } else { 1003 } else {
1001 info_ptr->validity = MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID; 1004 info_ptr->validity = MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID;
1002 info_ptr->dump_thread_id = handler_thread_; 1005 info_ptr->dump_thread_id = handler_thread_;
1003 info_ptr->requesting_thread_id = 0; 1006 info_ptr->requesting_thread_id = 0;
1004 } 1007 }
1005 1008
1006 return true; 1009 return true;
1007 } 1010 }
1008 1011
1009 } // namespace google_breakpad 1012 } // namespace google_breakpad
OLDNEW
« no previous file with comments | « src/client/mac/handler/exception_handler.cc ('k') | src/client/mac/handler/minidump_test.xcodeproj/project.pbxproj » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1004:630ec63f810e-tainted