diff --git a/src/tools/mac/dump_syms/dump_syms_tool.mm b/src/tools/mac/dump_syms/dump_syms_tool.mm index 827cea41..bd741220 100644 --- a/src/tools/mac/dump_syms/dump_syms_tool.mm +++ b/src/tools/mac/dump_syms/dump_syms_tool.mm @@ -1,3 +1,5 @@ +// -*- mode: c++ -*- + // Copyright (c) 2006, Google Inc. // All rights reserved. // @@ -27,49 +29,47 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// dump_syms_tool.m: Command line tool that uses the DumpSymbols class. +// dump_syms_tool.mm: Command line tool that uses the DumpSymbols class. // TODO(waylonis): accept stdin -#include #include +#include -#include "dump_syms.h" +#include "common/mac/dump_syms.h" #include "common/mac/macho_utilities.h" -typedef struct { +struct Options { + Options() : srcPath(), arch() { } NSString *srcPath; - NSString *arch; - NSString *uuidStr; - BOOL result; -} Options; + const NXArchInfo *arch; +}; //============================================================================= -static void Start(Options *options) { +static bool Start(const Options &options) { DumpSymbols *dump = [[DumpSymbols alloc] - initWithContentsOfFile:options->srcPath]; + initWithContentsOfFile:options.srcPath]; if (!dump) { fprintf(stderr, "%s is not a valid Mach-o file\n", - [options->srcPath fileSystemRepresentation]); - options->result = NO; - return; + [options.srcPath fileSystemRepresentation]); + return false; } - if (![dump setArchitecture:options->arch]) { + if (![dump setArchitecture:[NSString + stringWithUTF8String:options.arch->name]]) { fprintf(stderr, "Architecture: %s not available in %s\n", - [options->arch UTF8String], - [options->srcPath fileSystemRepresentation]); - options->result = NO; - return; + options.arch->name, + [options.srcPath fileSystemRepresentation]); + return false; } - options->result = [dump writeSymbolFile:@"-"]; + return [dump writeSymbolFile:@"-"]; } //============================================================================= static void Usage(int argc, const char *argv[]) { fprintf(stderr, "Output a Breakpad symbol file from a Mach-o file.\n"); - fprintf(stderr, "Usage: %s [-a ppc|i386|x86] \n", + fprintf(stderr, "Usage: %s [-a ARCHITECTURE] \n", argv[0]); fprintf(stderr, "\t-a: Architecture type [default: native]\n"); fprintf(stderr, "\t-h: Usage\n"); @@ -79,35 +79,22 @@ static void Usage(int argc, const char *argv[]) { //============================================================================= static void SetupOptions(int argc, const char *argv[], Options *options) { extern int optind; - const NXArchInfo *localArchInfo = NXGetLocalArchInfo(); signed char ch; - if (localArchInfo) { - if (localArchInfo->cputype & CPU_ARCH_ABI64) - options->arch = (localArchInfo->cputype == CPU_TYPE_POWERPC64) ? @"ppc64": - @"x86_64"; - else - options->arch = (localArchInfo->cputype == CPU_TYPE_POWERPC) ? @"ppc" : - @"x86"; - } + options->arch = NXGetLocalArchInfo(); while ((ch = getopt(argc, (char * const *)argv, "a:h?")) != -1) { switch (ch) { - case 'a': - if (strcmp("ppc", optarg) == 0) - options->arch = @"ppc"; - else if (strcmp("x86", optarg) == 0 || strcmp("i386", optarg) == 0) - options->arch = @"x86"; - else if (strcmp("ppc64", optarg) == 0) - options->arch = @"ppc64"; - else if (strcmp("x86_64", optarg) == 0) - options->arch = @"x86_64"; - else { + case 'a': { + const NXArchInfo *arch_info = NXGetArchInfoFromName(optarg); + if (!arch_info) { fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg); Usage(argc, argv); exit(1); } - break; + options->arch = arch_info; + break; + } case '?': case 'h': Usage(argc, argv); @@ -123,20 +110,20 @@ static void SetupOptions(int argc, const char *argv[], Options *options) { } options->srcPath = [[NSFileManager defaultManager] - stringWithFileSystemRepresentation:argv[optind] - length:strlen(argv[optind])]; + stringWithFileSystemRepresentation:argv[optind] + length:strlen(argv[optind])]; } //============================================================================= int main (int argc, const char * argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; Options options; + bool result; - bzero(&options, sizeof(Options)); SetupOptions(argc, argv, &options); - Start(&options); + result = Start(options); [pool release]; - return !options.result; + return !result; }