mac_fileid.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include <stdio.h>
  5. #include <string>
  6. #include "common/mac/arch_utilities.h"
  7. #include "common/mac/file_id.h"
  8. //TODO: move this somewhere common, this is copied from dump_symbols.cc
  9. // Format the Mach-O identifier in IDENTIFIER as a UUID with the
  10. // dashes removed.
  11. std::string FormatIdentifier(unsigned char identifier[16])
  12. {
  13. char identifier_string[40];
  14. google_breakpad::FileID::ConvertIdentifierToString(identifier, identifier_string,
  15. sizeof(identifier_string));
  16. std::string compacted(identifier_string);
  17. for(size_t i = compacted.find('-'); i != std::string::npos;
  18. i = compacted.find('-', i))
  19. compacted.erase(i, 1);
  20. compacted += '0';
  21. return compacted;
  22. }
  23. int main(int argc, char** argv)
  24. {
  25. if (argc != 2) {
  26. fprintf(stderr, "usage: fileid <object file>\n");
  27. return 1;
  28. }
  29. unsigned char identifier[16];
  30. google_breakpad::FileID file_id(argv[1]);
  31. // We should be able to use NXGetLocalArchInfo for this, but it returns
  32. // CPU_TYPE_X86 (which is the same as CPU_TYPE_I386) on x86_64 machines,
  33. // when our binary will typically have CPU_TYPE_X86_64 to match against.
  34. // So we hard code x86_64. In practice that's where we're running tests,
  35. // and that's what our debug binaries will contain.
  36. if (!file_id.MachoIdentifier(CPU_TYPE_X86_64, CPU_SUBTYPE_MULTIPLE,
  37. identifier)) {
  38. fprintf(stderr, "%s: unable to generate file identifier\n",
  39. argv[1]);
  40. return 1;
  41. }
  42. printf("%s\n", FormatIdentifier(identifier).c_str());
  43. return 0;
  44. }