* Renamed debug_delete_image_symbol_iterator() to

debug_delete_symbol_iterator().
* Added debug_create_file_symbol_iterator() which opens a shared object file.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30162 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-04-14 18:03:24 +00:00
parent d35b3513de
commit e52c3559d3
5 changed files with 106 additions and 7 deletions

View File

@ -70,7 +70,9 @@ status_t debug_lookup_symbol_address(debug_symbol_lookup_context *lookupContext,
status_t debug_create_image_symbol_iterator(
debug_symbol_lookup_context* lookupContext, image_id imageID,
debug_symbol_iterator** _iterator);
void debug_delete_image_symbol_iterator(debug_symbol_iterator* iterator);
status_t debug_create_file_symbol_iterator(const char* path,
debug_symbol_iterator** _iterator);
void debug_delete_symbol_iterator(debug_symbol_iterator* iterator);
status_t debug_next_image_symbol(debug_symbol_iterator* iterator,
char* nameBuffer, size_t nameBufferLength, int32* _symbolType,

View File

@ -71,13 +71,13 @@ Image::LoadSymbols(debug_symbol_lookup_context* lookupContext)
if (symbol == NULL || !symbols.AddItem(symbol)) {
delete symbol;
fprintf(stderr, "%s: Out of memory\n", kCommandName);
debug_delete_image_symbol_iterator(iterator);
debug_delete_symbol_iterator(iterator);
return B_NO_MEMORY;
}
}
}
debug_delete_image_symbol_iterator(iterator);
debug_delete_symbol_iterator(iterator);
// sort the symbols
fSymbolCount = symbols.CountItems();

View File

@ -199,10 +199,51 @@ ImageFile::~ImageFile()
status_t
ImageFile::Init(const image_info& info)
{
// just copy the image info
fInfo = info;
// load the file
addr_t textAddress;
size_t textSize;
status_t error = _LoadFile(info.name, &textAddress, &textSize);
if (error != B_OK)
return error;
// compute the load delta
fLoadDelta = (addr_t)fInfo.text - textAddress;
return B_OK;
}
status_t
ImageFile::Init(const char* path)
{
// load the file
addr_t textAddress;
size_t textSize;
status_t error = _LoadFile(path, &textAddress, &textSize);
if (error != B_OK)
return error;
// init the image info -- at least the part we use
fInfo.id = -1;
strlcpy(fInfo.name, path, sizeof(fInfo.name));
fInfo.text = (void*)textAddress;
fInfo.text_size = textSize;
// the image isn't loaded, so no delta
fLoadDelta = 0;
return B_OK;
}
status_t
ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize)
{
// open and stat() the file
fFD = open(fInfo.name, O_RDONLY);
fFD = open(path, O_RDONLY);
if (fFD < 0)
return errno;
@ -251,12 +292,15 @@ ImageFile::Init(const image_info& info)
Elf32_Shdr* sectionHeaders
= (Elf32_Shdr*)(fMappedFile + elfHeader->e_shoff);
// find the first segment -- we need its relative offset
// find the first segment -- we need its load address
*_textAddress = 0;
*_textSize = 0;
for (int32 i = 0; i < programHeaderCount; i++) {
Elf32_Phdr* header = (Elf32_Phdr*)
((uint8*)programHeaders + i * elfHeader->e_phentsize);
if (header->p_type == PT_LOAD) {
fLoadDelta = (addr_t)fInfo.text - header->p_vaddr;
*_textAddress = header->p_vaddr;
*_textSize = header->p_memsz;
break;
}
}

View File

@ -86,6 +86,11 @@ public:
virtual ~ImageFile();
status_t Init(const image_info& info);
status_t Init(const char* path);
private:
status_t _LoadFile(const char* path,
addr_t* _textAddress, size_t* _textSize);
private:
int fFD;

View File

@ -23,6 +23,19 @@ struct debug_symbol_lookup_context {
};
struct debug_symbol_iterator : BPrivate::Debug::SymbolIterator {
bool ownsImage;
debug_symbol_iterator()
:
ownsImage(false)
{
}
~debug_symbol_iterator()
{
if (ownsImage)
delete image;
}
};
@ -402,8 +415,43 @@ debug_create_image_symbol_iterator(debug_symbol_lookup_context* lookupContext,
}
status_t
debug_create_file_symbol_iterator(const char* path,
debug_symbol_iterator** _iterator)
{
if (path == NULL)
return B_BAD_VALUE;
// create the iterator
debug_symbol_iterator* iterator = new(std::nothrow) debug_symbol_iterator;
if (iterator == NULL)
return B_NO_MEMORY;
ObjectDeleter<debug_symbol_iterator> iteratorDeleter(iterator);
// create the image file
ImageFile* imageFile = new(std::nothrow) ImageFile;
if (imageFile == NULL)
return B_NO_MEMORY;
// init the iterator
iterator->image = imageFile;
iterator->ownsImage = true;
iterator->currentIndex = -1;
// init the image file
status_t error = imageFile->Init(path);
if (error != B_OK)
return error;
iteratorDeleter.Detach();
*_iterator = iterator;
return B_OK;
}
void
debug_delete_image_symbol_iterator(debug_symbol_iterator* iterator)
debug_delete_symbol_iterator(debug_symbol_iterator* iterator)
{
delete iterator;
}