OLD | NEW |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 namespace google_breakpad { | 50 namespace google_breakpad { |
51 | 51 |
52 #if __LP64__ | 52 #if __LP64__ |
53 #define LC_SEGMENT_ARCH LC_SEGMENT_64 | 53 #define LC_SEGMENT_ARCH LC_SEGMENT_64 |
54 #else | 54 #else |
55 #define LC_SEGMENT_ARCH LC_SEGMENT | 55 #define LC_SEGMENT_ARCH LC_SEGMENT |
56 #endif | 56 #endif |
57 | 57 |
58 // constructor when generating from within the crashed process | 58 // constructor when generating from within the crashed process |
59 MinidumpGenerator::MinidumpGenerator() | 59 MinidumpGenerator::MinidumpGenerator() |
60 : exception_type_(0), | 60 : writer_(), |
| 61 exception_type_(0), |
61 exception_code_(0), | 62 exception_code_(0), |
62 exception_subcode_(0), | 63 exception_subcode_(0), |
63 exception_thread_(0), | 64 exception_thread_(0), |
64 crashing_task_(mach_task_self()), | 65 crashing_task_(mach_task_self()), |
65 handler_thread_(mach_thread_self()), | 66 handler_thread_(mach_thread_self()), |
66 dynamic_images_(NULL) { | 67 dynamic_images_(NULL) { |
67 GatherSystemInformation(); | 68 GatherSystemInformation(); |
68 } | 69 } |
69 | 70 |
70 // constructor when generating from a different process than the | 71 // constructor when generating from a different process than the |
71 // crashed process | 72 // crashed process |
72 MinidumpGenerator::MinidumpGenerator(mach_port_t crashing_task, | 73 MinidumpGenerator::MinidumpGenerator(mach_port_t crashing_task, |
73 mach_port_t handler_thread) | 74 mach_port_t handler_thread) |
74 : exception_type_(0), | 75 : writer_(), |
| 76 exception_type_(0), |
75 exception_code_(0), | 77 exception_code_(0), |
76 exception_subcode_(0), | 78 exception_subcode_(0), |
77 exception_thread_(0), | 79 exception_thread_(0), |
78 crashing_task_(crashing_task), | 80 crashing_task_(crashing_task), |
79 handler_thread_(handler_thread) { | 81 handler_thread_(handler_thread), |
| 82 dynamic_images_(NULL) { |
80 if (crashing_task != mach_task_self()) { | 83 if (crashing_task != mach_task_self()) { |
81 dynamic_images_ = new DynamicImages(crashing_task_); | 84 dynamic_images_ = new DynamicImages(crashing_task_); |
82 } else { | 85 } else { |
83 dynamic_images_ = NULL; | 86 dynamic_images_ = NULL; |
84 } | 87 } |
85 | 88 |
86 GatherSystemInformation(); | 89 GatherSystemInformation(); |
87 } | 90 } |
88 | 91 |
89 MinidumpGenerator::~MinidumpGenerator() { | 92 MinidumpGenerator::~MinidumpGenerator() { |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 AddReg(r11); | 484 AddReg(r11); |
482 AddReg(r12); | 485 AddReg(r12); |
483 AddReg(r13); | 486 AddReg(r13); |
484 AddReg(r14); | 487 AddReg(r14); |
485 AddReg(r15); | 488 AddReg(r15); |
486 AddReg(rip); | 489 AddReg(rip); |
487 // according to AMD's software developer guide, bits above 18 are | 490 // according to AMD's software developer guide, bits above 18 are |
488 // not used in the flags register. Since the minidump format | 491 // not used in the flags register. Since the minidump format |
489 // specifies 32 bits for the flags register, we can truncate safely | 492 // specifies 32 bits for the flags register, we can truncate safely |
490 // with no loss. | 493 // with no loss. |
491 context_ptr->eflags = machine_state->__rflags; | 494 context_ptr->eflags = static_cast<u_int32_t>(machine_state->__rflags); |
492 AddReg(cs); | 495 AddReg(cs); |
493 AddReg(fs); | 496 AddReg(fs); |
494 AddReg(gs); | 497 AddReg(gs); |
495 #endif | 498 #endif |
496 #undef AddReg(a) | 499 #undef AddReg(a) |
497 | 500 |
498 return true; | 501 return true; |
499 } | 502 } |
500 #endif | 503 #endif |
501 | 504 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 | 723 |
721 memset(module, 0, sizeof(MDRawModule)); | 724 memset(module, 0, sizeof(MDRawModule)); |
722 | 725 |
723 MDLocationDescriptor string_location; | 726 MDLocationDescriptor string_location; |
724 | 727 |
725 const char* name = image->GetFilePath(); | 728 const char* name = image->GetFilePath(); |
726 if (!writer_.WriteString(name, 0, &string_location)) | 729 if (!writer_.WriteString(name, 0, &string_location)) |
727 return false; | 730 return false; |
728 | 731 |
729 module->base_of_image = image->GetVMAddr() + image->GetVMAddrSlide(); | 732 module->base_of_image = image->GetVMAddr() + image->GetVMAddrSlide(); |
730 module->size_of_image = image->GetVMSize(); | 733 module->size_of_image = static_cast<u_int32_t>(image->GetVMSize()); |
731 module->module_name_rva = string_location.rva; | 734 module->module_name_rva = string_location.rva; |
732 | 735 |
733 // We'll skip the executable module, because they don't have | 736 // We'll skip the executable module, because they don't have |
734 // LC_ID_DYLIB load commands, and the crash processing server gets | 737 // LC_ID_DYLIB load commands, and the crash processing server gets |
735 // version information from the Plist file, anyway. | 738 // version information from the Plist file, anyway. |
736 if (index != (uint32_t)FindExecutableModule()) { | 739 if (index != (uint32_t)FindExecutableModule()) { |
737 module->version_info.signature = MD_VSFIXEDFILEINFO_SIGNATURE; | 740 module->version_info.signature = MD_VSFIXEDFILEINFO_SIGNATURE; |
738 module->version_info.struct_version |= MD_VSFIXEDFILEINFO_VERSION; | 741 module->version_info.struct_version |= MD_VSFIXEDFILEINFO_VERSION; |
739 // Convert MAC dylib version format, which is a 32 bit number, to the | 742 // Convert MAC dylib version format, which is a 32 bit number, to the |
740 // format used by minidump. The mac format is <16 bits>.<8 bits>.<8 bits> | 743 // format used by minidump. The mac format is <16 bits>.<8 bits>.<8 bits> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 const breakpad_mach_segment_command *seg = | 790 const breakpad_mach_segment_command *seg = |
788 reinterpret_cast<const breakpad_mach_segment_command *>(cmd); | 791 reinterpret_cast<const breakpad_mach_segment_command *>(cmd); |
789 | 792 |
790 if (!strcmp(seg->segname, "__TEXT")) { | 793 if (!strcmp(seg->segname, "__TEXT")) { |
791 MDLocationDescriptor string_location; | 794 MDLocationDescriptor string_location; |
792 | 795 |
793 if (!writer_.WriteString(name, 0, &string_location)) | 796 if (!writer_.WriteString(name, 0, &string_location)) |
794 return false; | 797 return false; |
795 | 798 |
796 module->base_of_image = seg->vmaddr + slide; | 799 module->base_of_image = seg->vmaddr + slide; |
797 module->size_of_image = seg->vmsize; | 800 module->size_of_image = static_cast<u_int32_t>(seg->vmsize); |
798 module->module_name_rva = string_location.rva; | 801 module->module_name_rva = string_location.rva; |
799 | 802 |
800 if (!WriteCVRecord(module, cpu_type, name)) | 803 if (!WriteCVRecord(module, cpu_type, name)) |
801 return false; | 804 return false; |
802 | 805 |
803 return true; | 806 return true; |
804 } | 807 } |
805 } | 808 } |
806 | 809 |
807 cmd = reinterpret_cast<struct load_command*>((char *)cmd + cmd->cmdsize); | 810 cmd = reinterpret_cast<struct load_command*>((char *)cmd + cmd->cmdsize); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 MD_MISCINFO_FLAGS1_PROCESS_TIMES | | 939 MD_MISCINFO_FLAGS1_PROCESS_TIMES | |
937 MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO; | 940 MD_MISCINFO_FLAGS1_PROCESSOR_POWER_INFO; |
938 | 941 |
939 // Process ID | 942 // Process ID |
940 info_ptr->process_id = getpid(); | 943 info_ptr->process_id = getpid(); |
941 | 944 |
942 // Times | 945 // Times |
943 struct rusage usage; | 946 struct rusage usage; |
944 if (getrusage(RUSAGE_SELF, &usage) != -1) { | 947 if (getrusage(RUSAGE_SELF, &usage) != -1) { |
945 // Omit the fractional time since the MDRawMiscInfo only wants seconds | 948 // Omit the fractional time since the MDRawMiscInfo only wants seconds |
946 info_ptr->process_user_time = usage.ru_utime.tv_sec; | 949 info_ptr->process_user_time = |
947 info_ptr->process_kernel_time = usage.ru_stime.tv_sec; | 950 static_cast<u_int32_t>(usage.ru_utime.tv_sec); |
| 951 info_ptr->process_kernel_time = |
| 952 static_cast<u_int32_t>(usage.ru_stime.tv_sec); |
948 } | 953 } |
949 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, info_ptr->process_id }; | 954 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, info_ptr->process_id }; |
950 size_t size; | 955 size_t size; |
951 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &size, NULL, 0)) { | 956 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &size, NULL, 0)) { |
952 mach_vm_address_t addr; | 957 mach_vm_address_t addr; |
953 if (mach_vm_allocate(mach_task_self(), | 958 if (mach_vm_allocate(mach_task_self(), |
954 &addr, | 959 &addr, |
955 size, | 960 size, |
956 true) == KERN_SUCCESS) { | 961 true) == KERN_SUCCESS) { |
957 struct kinfo_proc *proc = (struct kinfo_proc *)addr; | 962 struct kinfo_proc *proc = (struct kinfo_proc *)addr; |
958 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), proc, &size, NULL, 0)) | 963 if (!sysctl(mib, sizeof(mib) / sizeof(mib[0]), proc, &size, NULL, 0)) |
959 info_ptr->process_create_time = proc->kp_proc.p_starttime.tv_sec; | 964 info_ptr->process_create_time = |
| 965 static_cast<u_int32_t>(proc->kp_proc.p_starttime.tv_sec); |
960 mach_vm_deallocate(mach_task_self(), addr, size); | 966 mach_vm_deallocate(mach_task_self(), addr, size); |
961 } | 967 } |
962 } | 968 } |
963 | 969 |
964 // Speed | 970 // Speed |
965 uint64_t speed; | 971 uint64_t speed; |
966 size = sizeof(speed); | 972 size = sizeof(speed); |
967 sysctlbyname("hw.cpufrequency_max", &speed, &size, NULL, 0); | 973 sysctlbyname("hw.cpufrequency_max", &speed, &size, NULL, 0); |
968 info_ptr->processor_max_mhz = speed / (1000 * 1000); | 974 info_ptr->processor_max_mhz = static_cast<u_int32_t>(speed / (1000000)); |
969 info_ptr->processor_mhz_limit = speed / (1000 * 1000); | 975 info_ptr->processor_mhz_limit = static_cast<u_int32_t>(speed / (1000000)); |
970 size = sizeof(speed); | 976 size = sizeof(speed); |
971 sysctlbyname("hw.cpufrequency", &speed, &size, NULL, 0); | 977 sysctlbyname("hw.cpufrequency", &speed, &size, NULL, 0); |
972 info_ptr->processor_current_mhz = speed / (1000 * 1000); | 978 info_ptr->processor_current_mhz = static_cast<u_int32_t>(speed / (1000000)); |
973 | 979 |
974 return true; | 980 return true; |
975 } | 981 } |
976 | 982 |
977 bool MinidumpGenerator::WriteBreakpadInfoStream( | 983 bool MinidumpGenerator::WriteBreakpadInfoStream( |
978 MDRawDirectory *breakpad_info_stream) { | 984 MDRawDirectory *breakpad_info_stream) { |
979 TypedMDRVA<MDRawBreakpadInfo> info(&writer_); | 985 TypedMDRVA<MDRawBreakpadInfo> info(&writer_); |
980 | 986 |
981 if (!info.Allocate()) | 987 if (!info.Allocate()) |
982 return false; | 988 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
993 } else { | 999 } else { |
994 info_ptr->validity = MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID; | 1000 info_ptr->validity = MD_BREAKPAD_INFO_VALID_DUMP_THREAD_ID; |
995 info_ptr->dump_thread_id = handler_thread_; | 1001 info_ptr->dump_thread_id = handler_thread_; |
996 info_ptr->requesting_thread_id = 0; | 1002 info_ptr->requesting_thread_id = 0; |
997 } | 1003 } |
998 | 1004 |
999 return true; | 1005 return true; |
1000 } | 1006 } |
1001 | 1007 |
1002 } // namespace google_breakpad | 1008 } // namespace google_breakpad |
OLD | NEW |