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
This commit is contained in:
parent
35c41e00ee
commit
75ce593891
@ -1,3 +1,5 @@
|
|||||||
|
// -*- mode: c++ -*-
|
||||||
|
|
||||||
// Copyright (c) 2006, Google Inc.
|
// Copyright (c) 2006, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@ -27,49 +29,47 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// 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
|
// TODO(waylonis): accept stdin
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <mach-o/arch.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"
|
#include "common/mac/macho_utilities.h"
|
||||||
|
|
||||||
typedef struct {
|
struct Options {
|
||||||
|
Options() : srcPath(), arch() { }
|
||||||
NSString *srcPath;
|
NSString *srcPath;
|
||||||
NSString *arch;
|
const NXArchInfo *arch;
|
||||||
NSString *uuidStr;
|
};
|
||||||
BOOL result;
|
|
||||||
} Options;
|
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
static void Start(Options *options) {
|
static bool Start(const Options &options) {
|
||||||
DumpSymbols *dump = [[DumpSymbols alloc]
|
DumpSymbols *dump = [[DumpSymbols alloc]
|
||||||
initWithContentsOfFile:options->srcPath];
|
initWithContentsOfFile:options.srcPath];
|
||||||
|
|
||||||
if (!dump) {
|
if (!dump) {
|
||||||
fprintf(stderr, "%s is not a valid Mach-o file\n",
|
fprintf(stderr, "%s is not a valid Mach-o file\n",
|
||||||
[options->srcPath fileSystemRepresentation]);
|
[options.srcPath fileSystemRepresentation]);
|
||||||
options->result = NO;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![dump setArchitecture:options->arch]) {
|
if (![dump setArchitecture:[NSString
|
||||||
|
stringWithUTF8String:options.arch->name]]) {
|
||||||
fprintf(stderr, "Architecture: %s not available in %s\n",
|
fprintf(stderr, "Architecture: %s not available in %s\n",
|
||||||
[options->arch UTF8String],
|
options.arch->name,
|
||||||
[options->srcPath fileSystemRepresentation]);
|
[options.srcPath fileSystemRepresentation]);
|
||||||
options->result = NO;
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options->result = [dump writeSymbolFile:@"-"];
|
return [dump writeSymbolFile:@"-"];
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
static void Usage(int argc, const char *argv[]) {
|
static void Usage(int argc, const char *argv[]) {
|
||||||
fprintf(stderr, "Output a Breakpad symbol file from a Mach-o file.\n");
|
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]);
|
argv[0]);
|
||||||
fprintf(stderr, "\t-a: Architecture type [default: native]\n");
|
fprintf(stderr, "\t-a: Architecture type [default: native]\n");
|
||||||
fprintf(stderr, "\t-h: Usage\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) {
|
static void SetupOptions(int argc, const char *argv[], Options *options) {
|
||||||
extern int optind;
|
extern int optind;
|
||||||
const NXArchInfo *localArchInfo = NXGetLocalArchInfo();
|
|
||||||
signed char ch;
|
signed char ch;
|
||||||
|
|
||||||
if (localArchInfo) {
|
options->arch = NXGetLocalArchInfo();
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, (char * const *)argv, "a:h?")) != -1) {
|
while ((ch = getopt(argc, (char * const *)argv, "a:h?")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a': {
|
||||||
if (strcmp("ppc", optarg) == 0)
|
const NXArchInfo *arch_info = NXGetArchInfoFromName(optarg);
|
||||||
options->arch = @"ppc";
|
if (!arch_info) {
|
||||||
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 {
|
|
||||||
fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg);
|
fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg);
|
||||||
Usage(argc, argv);
|
Usage(argc, argv);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
options->arch = arch_info;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
Usage(argc, argv);
|
Usage(argc, argv);
|
||||||
@ -131,12 +118,12 @@ static void SetupOptions(int argc, const char *argv[], Options *options) {
|
|||||||
int main (int argc, const char * argv[]) {
|
int main (int argc, const char * argv[]) {
|
||||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
Options options;
|
Options options;
|
||||||
|
bool result;
|
||||||
|
|
||||||
bzero(&options, sizeof(Options));
|
|
||||||
SetupOptions(argc, argv, &options);
|
SetupOptions(argc, argv, &options);
|
||||||
Start(&options);
|
result = Start(options);
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
return !options.result;
|
return !result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user