Skip to content

Commit

Permalink
Move Address_str into dynProcess.C
Browse files Browse the repository at this point in the history
It's only ever used there.
  • Loading branch information
hainest committed Nov 6, 2023
1 parent 1154f49 commit d5828aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
19 changes: 0 additions & 19 deletions common/src/Types.C
Expand Up @@ -42,22 +42,3 @@ void Address_chk ()
{
assert (sizeof(Address) == sizeof(void*));
}

static const unsigned int _numaddrstrs=8;
// maximum number of addresses per outstanding printf!
static char _addrstr[_numaddrstrs][19]; // "0x"+16+'\0'

// Format an address string according to the size of the Address type.
// Note that "%x" outputs incorrect/incomplete addresses, and that "%lx"
// or system-dependent "%p" (generally also requiring a typecast to (void*))
// must be used instead!
char *Address_str (Address addr)
{
static int i=0;
i=(i+1)%_numaddrstrs;
if (sizeof(Address) == sizeof(int))
snprintf(_addrstr[i],19,"0x%08X",(unsigned int)addr);
else
snprintf(_addrstr[i],19,"0x%016lX",(unsigned long)addr);
return (_addrstr[i]);
}
1 change: 0 additions & 1 deletion common/src/Types.h
Expand Up @@ -94,7 +94,6 @@ typedef struct maps_entries {
#include "common/h/util.h"

COMMON_EXPORT void Address_chk ();
COMMON_EXPORT char *Address_str (Address addr);

// NB: this is probably inappropriate for 64-bit addresses!
inline unsigned hash_address(const Address& addr) {
Expand Down
21 changes: 21 additions & 0 deletions dyninstAPI/src/dynProcess.C
Expand Up @@ -55,6 +55,27 @@

#include <sstream>

namespace {
// maximum number of addresses per outstanding printf!
const unsigned int _numaddrstrs=8;
char _addrstr[_numaddrstrs][19]; // "0x"+16+'\0'

// Format an address string according to the size of the Address type.
// Note that "%x" outputs incorrect/incomplete addresses, and that "%lx"
// or system-dependent "%p" (generally also requiring a typecast to (void*))
// must be used instead!
char *Address_str (Address addr)
{
static int i=0;
i=(i+1)%_numaddrstrs;
if (sizeof(Address) == sizeof(int))
snprintf(_addrstr[i],19,"0x%08X",(unsigned int)addr);
else
snprintf(_addrstr[i],19,"0x%016lX",(unsigned long)addr);
return (_addrstr[i]);
}
}

using namespace Dyninst::ProcControlAPI;
using std::map;
using std::vector;
Expand Down

0 comments on commit d5828aa

Please sign in to comment.