Breakpad Mac Dumper: Fix compilation warnings on OS X 10.6

Breakpad's Macintosh symbol dumper uses deprecated functions for
dealing with mixed-endianness code. This patch provides an overloaded
function, ByteSwap, that automatically chooses the OSSwap* functions
from <libkern/OSByteOrder.h> appropriate for its argument's
size.

This patch does *not* address warnings in src/common/mac/dump_syms.mm,
because that code is about to be replaced entirely; there's no reason to
bother reviewing a big, detailed patch against it.

a=jimblandy, r=mark


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@589 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
jimblandy 2010-05-05 17:36:16 +00:00
parent 25b512d64d
commit 52a508dfe2
4 changed files with 82 additions and 30 deletions

48
src/common/mac/byteswap.h Normal file
View File

@ -0,0 +1,48 @@
// -*- mode: c++ -*-
// Copyright (c) 2010, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Original author: Jim Blandy <jim@mozilla.com> <jimb@red-bean.com>
// byteswap.h: Overloaded functions for conveniently byteswapping values.
#ifndef COMMON_MAC_BYTESWAP_H_
#define COMMON_MAC_BYTESWAP_H_
#include <libkern/OSByteOrder.h>
static inline uint16_t ByteSwap(uint16_t v) { return OSSwapInt16(v); }
static inline uint32_t ByteSwap(uint32_t v) { return OSSwapInt32(v); }
static inline uint64_t ByteSwap(uint64_t v) { return OSSwapInt64(v); }
static inline int16_t ByteSwap(int16_t v) { return OSSwapInt16(v); }
static inline int32_t ByteSwap(int32_t v) { return OSSwapInt32(v); }
static inline int64_t ByteSwap(int64_t v) { return OSSwapInt64(v); }
#endif // COMMON_MAC_BYTESWAP_H_

View File

@ -31,43 +31,44 @@
//
// Author: Dave Camp
#include "common/mac/byteswap.h"
#include "common/mac/macho_utilities.h"
void breakpad_swap_uuid_command(struct breakpad_uuid_command *uc,
enum NXByteOrder target_byte_order)
{
uc->cmd = NXSwapLong(uc->cmd);
uc->cmdsize = NXSwapLong(uc->cmdsize);
uc->cmd = ByteSwap(uc->cmd);
uc->cmdsize = ByteSwap(uc->cmdsize);
}
void breakpad_swap_segment_command_64(struct segment_command_64 *sg,
enum NXByteOrder target_byte_order)
{
sg->cmd = NXSwapLong(sg->cmd);
sg->cmdsize = NXSwapLong(sg->cmdsize);
sg->cmd = ByteSwap(sg->cmd);
sg->cmdsize = ByteSwap(sg->cmdsize);
sg->vmaddr = NXSwapLongLong(sg->vmaddr);
sg->vmsize = NXSwapLongLong(sg->vmsize);
sg->fileoff = NXSwapLongLong(sg->fileoff);
sg->filesize = NXSwapLongLong(sg->filesize);
sg->vmaddr = ByteSwap(sg->vmaddr);
sg->vmsize = ByteSwap(sg->vmsize);
sg->fileoff = ByteSwap(sg->fileoff);
sg->filesize = ByteSwap(sg->filesize);
sg->maxprot = NXSwapLong(sg->maxprot);
sg->initprot = NXSwapLong(sg->initprot);
sg->nsects = NXSwapLong(sg->nsects);
sg->flags = NXSwapLong(sg->flags);
sg->maxprot = ByteSwap(sg->maxprot);
sg->initprot = ByteSwap(sg->initprot);
sg->nsects = ByteSwap(sg->nsects);
sg->flags = ByteSwap(sg->flags);
}
void breakpad_swap_mach_header_64(struct mach_header_64 *mh,
enum NXByteOrder target_byte_order)
{
mh->magic = NXSwapLong(mh->magic);
mh->cputype = NXSwapLong(mh->cputype);
mh->cpusubtype = NXSwapLong(mh->cpusubtype);
mh->filetype = NXSwapLong(mh->filetype);
mh->ncmds = NXSwapLong(mh->ncmds);
mh->sizeofcmds = NXSwapLong(mh->sizeofcmds);
mh->flags = NXSwapLong(mh->flags);
mh->reserved = NXSwapLong(mh->reserved);
mh->magic = ByteSwap(mh->magic);
mh->cputype = ByteSwap(mh->cputype);
mh->cpusubtype = ByteSwap(mh->cpusubtype);
mh->filetype = ByteSwap(mh->filetype);
mh->ncmds = ByteSwap(mh->ncmds);
mh->sizeofcmds = ByteSwap(mh->sizeofcmds);
mh->flags = ByteSwap(mh->flags);
mh->reserved = ByteSwap(mh->reserved);
}
void breakpad_swap_section_64(struct section_64 *s,
@ -75,15 +76,15 @@ void breakpad_swap_section_64(struct section_64 *s,
enum NXByteOrder target_byte_order)
{
for (uint32_t i = 0; i < nsects; i++) {
s[i].addr = NXSwapLongLong(s[i].addr);
s[i].size = NXSwapLongLong(s[i].size);
s[i].addr = ByteSwap(s[i].addr);
s[i].size = ByteSwap(s[i].size);
s[i].offset = NXSwapLong(s[i].offset);
s[i].align = NXSwapLong(s[i].align);
s[i].reloff = NXSwapLong(s[i].reloff);
s[i].nreloc = NXSwapLong(s[i].nreloc);
s[i].flags = NXSwapLong(s[i].flags);
s[i].reserved1 = NXSwapLong(s[i].reserved1);
s[i].reserved2 = NXSwapLong(s[i].reserved2);
s[i].offset = ByteSwap(s[i].offset);
s[i].align = ByteSwap(s[i].align);
s[i].reloff = ByteSwap(s[i].reloff);
s[i].nreloc = ByteSwap(s[i].nreloc);
s[i].flags = ByteSwap(s[i].flags);
s[i].reserved1 = ByteSwap(s[i].reserved1);
s[i].reserved2 = ByteSwap(s[i].reserved2);
}
}

View File

@ -43,6 +43,7 @@ extern "C" { // necessary for Leopard
#include <unistd.h>
}
#include "common/mac/byteswap.h"
#include "common/mac/macho_walker.h"
#include "common/mac/macho_utilities.h"
@ -136,7 +137,7 @@ bool MachoWalker::FindHeader(int cpu_type, off_t &offset) {
return false;
if (magic == MH_CIGAM || magic == MH_CIGAM_64)
header_cpu_type = NXSwapInt(header_cpu_type);
header_cpu_type = ByteSwap(header_cpu_type);
if (valid_cpu_type != header_cpu_type)
return false;

View File

@ -45,6 +45,7 @@
9BE650440B52F6D800611104 /* macho_id.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = macho_id.h; path = ../../../common/mac/macho_id.h; sourceTree = SOURCE_ROOT; };
9BE650450B52F6D800611104 /* macho_walker.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = macho_walker.cc; path = ../../../common/mac/macho_walker.cc; sourceTree = SOURCE_ROOT; };
9BE650460B52F6D800611104 /* macho_walker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = macho_walker.h; path = ../../../common/mac/macho_walker.h; sourceTree = SOURCE_ROOT; };
B8E8CA0C1156C854009E61B2 /* byteswap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = byteswap.h; path = ../../../common/mac/byteswap.h; sourceTree = SOURCE_ROOT; };
F95B422B0E0E22D100DBDE83 /* bytereader-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "bytereader-inl.h"; path = "../../../common/dwarf/bytereader-inl.h"; sourceTree = SOURCE_ROOT; };
F95B422C0E0E22D100DBDE83 /* bytereader.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bytereader.cc; path = ../../../common/dwarf/bytereader.cc; sourceTree = SOURCE_ROOT; };
F95B422D0E0E22D100DBDE83 /* bytereader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bytereader.h; path = ../../../common/dwarf/bytereader.h; sourceTree = SOURCE_ROOT; };
@ -72,6 +73,7 @@
isa = PBXGroup;
children = (
F9F5344B0E7C8FFC0012363F /* DWARF */,
B8E8CA0C1156C854009E61B2 /* byteswap.h */,
557800890BE1F3AB00EC23E0 /* macho_utilities.cc */,
5578008A0BE1F3AB00EC23E0 /* macho_utilities.h */,
9BE650410B52F6D800611104 /* file_id.cc */,