Added debug_get_symbol_iterator_image_info() to get an image_info from a
symbol iterator. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30168 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+28
-34
@@ -39,7 +39,6 @@ Image::~Image()
|
|||||||
|
|
||||||
SymbolTableBasedImage::SymbolTableBasedImage()
|
SymbolTableBasedImage::SymbolTableBasedImage()
|
||||||
:
|
:
|
||||||
fInfo(),
|
|
||||||
fLoadDelta(0),
|
fLoadDelta(0),
|
||||||
fSymbolTable(NULL),
|
fSymbolTable(NULL),
|
||||||
fStringTable(NULL),
|
fStringTable(NULL),
|
||||||
@@ -54,34 +53,6 @@ SymbolTableBasedImage::~SymbolTableBasedImage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
image_id
|
|
||||||
SymbolTableBasedImage::ID() const
|
|
||||||
{
|
|
||||||
return fInfo.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
SymbolTableBasedImage::Name() const
|
|
||||||
{
|
|
||||||
return fInfo.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addr_t
|
|
||||||
SymbolTableBasedImage::TextAddress() const
|
|
||||||
{
|
|
||||||
return (addr_t)fInfo.text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t
|
|
||||||
SymbolTableBasedImage::TextSize() const
|
|
||||||
{
|
|
||||||
return fInfo.text_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const Elf32_Sym*
|
const Elf32_Sym*
|
||||||
SymbolTableBasedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
|
SymbolTableBasedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
|
||||||
const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const
|
const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const
|
||||||
@@ -205,7 +176,10 @@ ImageFile::Init(const image_info& info)
|
|||||||
// load the file
|
// load the file
|
||||||
addr_t textAddress;
|
addr_t textAddress;
|
||||||
size_t textSize;
|
size_t textSize;
|
||||||
status_t error = _LoadFile(info.name, &textAddress, &textSize);
|
addr_t dataAddress;
|
||||||
|
size_t dataSize;
|
||||||
|
status_t error = _LoadFile(info.name, &textAddress, &textSize, &dataAddress,
|
||||||
|
&dataSize);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -222,15 +196,27 @@ ImageFile::Init(const char* path)
|
|||||||
// load the file
|
// load the file
|
||||||
addr_t textAddress;
|
addr_t textAddress;
|
||||||
size_t textSize;
|
size_t textSize;
|
||||||
status_t error = _LoadFile(path, &textAddress, &textSize);
|
addr_t dataAddress;
|
||||||
|
size_t dataSize;
|
||||||
|
status_t error = _LoadFile(path, &textAddress, &textSize, &dataAddress,
|
||||||
|
&dataSize);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
// init the image info -- at least the part we use
|
// init the image info
|
||||||
fInfo.id = -1;
|
fInfo.id = -1;
|
||||||
|
fInfo.type = B_LIBRARY_IMAGE;
|
||||||
|
fInfo.sequence = 0;
|
||||||
|
fInfo.init_order = 0;
|
||||||
|
fInfo.init_routine = 0;
|
||||||
|
fInfo.term_routine = 0;
|
||||||
|
fInfo.device = -1;
|
||||||
|
fInfo.node = -1;
|
||||||
strlcpy(fInfo.name, path, sizeof(fInfo.name));
|
strlcpy(fInfo.name, path, sizeof(fInfo.name));
|
||||||
fInfo.text = (void*)textAddress;
|
fInfo.text = (void*)textAddress;
|
||||||
|
fInfo.data = (void*)dataAddress;
|
||||||
fInfo.text_size = textSize;
|
fInfo.text_size = textSize;
|
||||||
|
fInfo.data_size = dataSize;
|
||||||
|
|
||||||
// the image isn't loaded, so no delta
|
// the image isn't loaded, so no delta
|
||||||
fLoadDelta = 0;
|
fLoadDelta = 0;
|
||||||
@@ -240,7 +226,8 @@ ImageFile::Init(const char* path)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize)
|
ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize,
|
||||||
|
addr_t* _dataAddress, size_t* _dataSize)
|
||||||
{
|
{
|
||||||
// open and stat() the file
|
// open and stat() the file
|
||||||
fFD = open(path, O_RDONLY);
|
fFD = open(path, O_RDONLY);
|
||||||
@@ -292,18 +279,25 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize)
|
|||||||
Elf32_Shdr* sectionHeaders
|
Elf32_Shdr* sectionHeaders
|
||||||
= (Elf32_Shdr*)(fMappedFile + elfHeader->e_shoff);
|
= (Elf32_Shdr*)(fMappedFile + elfHeader->e_shoff);
|
||||||
|
|
||||||
// find the first segment -- we need its load address
|
// find the text and data segment -- we need load address and size
|
||||||
*_textAddress = 0;
|
*_textAddress = 0;
|
||||||
*_textSize = 0;
|
*_textSize = 0;
|
||||||
|
*_dataAddress = 0;
|
||||||
|
*_dataSize = 0;
|
||||||
for (int32 i = 0; i < programHeaderCount; i++) {
|
for (int32 i = 0; i < programHeaderCount; i++) {
|
||||||
Elf32_Phdr* header = (Elf32_Phdr*)
|
Elf32_Phdr* header = (Elf32_Phdr*)
|
||||||
((uint8*)programHeaders + i * elfHeader->e_phentsize);
|
((uint8*)programHeaders + i * elfHeader->e_phentsize);
|
||||||
if (header->p_type == PT_LOAD) {
|
if (header->p_type == PT_LOAD) {
|
||||||
|
if ((header->p_flags & PF_WRITE) == 0) {
|
||||||
*_textAddress = header->p_vaddr;
|
*_textAddress = header->p_vaddr;
|
||||||
*_textSize = header->p_memsz;
|
*_textSize = header->p_memsz;
|
||||||
|
} else {
|
||||||
|
*_dataAddress = header->p_vaddr;
|
||||||
|
*_dataSize = header->p_memsz;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find the symbol table
|
// find the symbol table
|
||||||
for (int32 i = 0; i < elfHeader->e_shnum; i++) {
|
for (int32 i = 0; i < elfHeader->e_shnum; i++) {
|
||||||
|
|||||||
+11
-11
@@ -28,10 +28,12 @@ public:
|
|||||||
Image();
|
Image();
|
||||||
virtual ~Image();
|
virtual ~Image();
|
||||||
|
|
||||||
virtual image_id ID() const = 0;
|
const image_info& Info() const { return fInfo; }
|
||||||
virtual const char* Name() const = 0;
|
image_id ID() const { return fInfo.id; }
|
||||||
virtual addr_t TextAddress() const = 0;
|
const char* Name() const { return fInfo.name; }
|
||||||
virtual size_t TextSize() const = 0;
|
addr_t TextAddress() const
|
||||||
|
{ return (addr_t)fInfo.text; }
|
||||||
|
size_t TextSize() const { return fInfo.text_size; }
|
||||||
|
|
||||||
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
||||||
addr_t* _baseAddress,
|
addr_t* _baseAddress,
|
||||||
@@ -43,6 +45,9 @@ public:
|
|||||||
size_t* _symbolNameLen,
|
size_t* _symbolNameLen,
|
||||||
addr_t* _symbolAddress, size_t* _symbolSize,
|
addr_t* _symbolAddress, size_t* _symbolSize,
|
||||||
int32* _symbolType) const = 0;
|
int32* _symbolType) const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
image_info fInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -51,11 +56,6 @@ public:
|
|||||||
SymbolTableBasedImage();
|
SymbolTableBasedImage();
|
||||||
virtual ~SymbolTableBasedImage();
|
virtual ~SymbolTableBasedImage();
|
||||||
|
|
||||||
virtual image_id ID() const ;
|
|
||||||
virtual const char* Name() const;
|
|
||||||
virtual addr_t TextAddress() const;
|
|
||||||
virtual size_t TextSize() const;
|
|
||||||
|
|
||||||
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
||||||
addr_t* _baseAddress,
|
addr_t* _baseAddress,
|
||||||
const char** _symbolName,
|
const char** _symbolName,
|
||||||
@@ -71,7 +71,6 @@ protected:
|
|||||||
size_t _SymbolNameLen(const char* symbolName) const;
|
size_t _SymbolNameLen(const char* symbolName) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
image_info fInfo;
|
|
||||||
addr_t fLoadDelta;
|
addr_t fLoadDelta;
|
||||||
Elf32_Sym* fSymbolTable;
|
Elf32_Sym* fSymbolTable;
|
||||||
char* fStringTable;
|
char* fStringTable;
|
||||||
@@ -90,7 +89,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _LoadFile(const char* path,
|
status_t _LoadFile(const char* path,
|
||||||
addr_t* _textAddress, size_t* _textSize);
|
addr_t* _textAddress, size_t* _textSize,
|
||||||
|
addr_t* _dataAddress, size_t* _dataSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fFD;
|
int fFD;
|
||||||
|
|||||||
@@ -196,11 +196,6 @@ public:
|
|||||||
const image_t* image, int32 symbolCount);
|
const image_t* image, int32 symbolCount);
|
||||||
virtual ~LoadedImage();
|
virtual ~LoadedImage();
|
||||||
|
|
||||||
virtual image_id ID() const;
|
|
||||||
virtual const char* Name() const;
|
|
||||||
virtual addr_t TextAddress() const;
|
|
||||||
virtual size_t TextSize() const;
|
|
||||||
|
|
||||||
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
virtual const Elf32_Sym* LookupSymbol(addr_t address,
|
||||||
addr_t* _baseAddress,
|
addr_t* _baseAddress,
|
||||||
const char** _symbolName,
|
const char** _symbolName,
|
||||||
@@ -526,6 +521,20 @@ SymbolLookup::LoadedImage::LoadedImage(SymbolLookup* symbolLookup,
|
|||||||
fSymbolCount(symbolCount),
|
fSymbolCount(symbolCount),
|
||||||
fTextDelta(image->regions[0].delta)
|
fTextDelta(image->regions[0].delta)
|
||||||
{
|
{
|
||||||
|
// init info
|
||||||
|
fInfo.id = fImage->id;
|
||||||
|
fInfo.type = fImage->type;
|
||||||
|
fInfo.sequence = 0;
|
||||||
|
fInfo.init_order = 0;
|
||||||
|
fInfo.init_routine = (void (*)())fImage->init_routine;
|
||||||
|
fInfo.term_routine = (void (*)())fImage->term_routine;
|
||||||
|
fInfo.device = -1;
|
||||||
|
fInfo.node = -1;
|
||||||
|
strlcpy(fInfo.name, fImage->path, sizeof(fInfo.name));
|
||||||
|
fInfo.text = (void*)fImage->regions[0].vmstart;
|
||||||
|
fInfo.data = (void*)fImage->regions[1].vmstart;
|
||||||
|
fInfo.text_size = fImage->regions[0].vmsize;
|
||||||
|
fInfo.data_size = fImage->regions[1].vmsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -534,34 +543,6 @@ SymbolLookup::LoadedImage::~LoadedImage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
image_id
|
|
||||||
SymbolLookup::LoadedImage::ID() const
|
|
||||||
{
|
|
||||||
return fImage->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
SymbolLookup::LoadedImage::Name() const
|
|
||||||
{
|
|
||||||
return fImage->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addr_t
|
|
||||||
SymbolLookup::LoadedImage::TextAddress() const
|
|
||||||
{
|
|
||||||
return fImage->regions[0].vmstart;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t
|
|
||||||
SymbolLookup::LoadedImage::TextSize() const
|
|
||||||
{
|
|
||||||
return fImage->regions[0].vmsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const Elf32_Sym*
|
const Elf32_Sym*
|
||||||
SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
|
SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
|
||||||
const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const
|
const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const
|
||||||
|
|||||||
@@ -490,3 +490,15 @@ debug_next_image_symbol(debug_symbol_iterator* iterator, char* nameBuffer,
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
debug_get_symbol_iterator_image_info(debug_symbol_iterator* iterator,
|
||||||
|
image_info* info)
|
||||||
|
{
|
||||||
|
if (iterator == NULL || iterator->image == NULL || info == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
*info = iterator->image->Info();
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user