aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorted.mielczarek <ted.mielczarek@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-06-25 16:56:27 +0000
committerted.mielczarek <ted.mielczarek@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-06-25 16:56:27 +0000
commit75ce5938919e1e195a71329fee63971ed2a218fc (patch)
tree41f06a9b492467c936bea5f440e970f1f10d4abb /src/tools
parentBreakpad Mac symbol dumper: Add new Mach-O reader class. (diff)
downloadbreakpad-75ce5938919e1e195a71329fee63971ed2a218fc.tar.xz
Breakpad Mac dumper: Change the dumper to be more C++-ish.
Instead of using bzero in main, use constructors to initialize the Options structure. Use C++ bool, not Objective-C BOOL. Use a const NXArchInfo * to represent the architecture name, so that we can use the NXGetLocalArchInfo, NXGetArchInfoFromName, etc. to handle things. Delete the 'uuidStr' member; it is unused. Leave Options::srcPath as an NSString, so that we can continue to use the filesystem path abstraction methods provided by the Foundation framework. A=jimb R=mark git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@611 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/mac/dump_syms/dump_syms_tool.mm77
1 files changed, 32 insertions, 45 deletions
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 <unistd.h>
#include <mach-o/arch.h>
+#include <unistd.h>
-#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] <Mach-o file>\n",
+ fprintf(stderr, "Usage: %s [-a ARCHITECTURE] <Mach-o file>\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;
}