Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Commit

Permalink
Added std::string viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 7, 2008
1 parent b7e2c11 commit 42e33be
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .hgignore
Expand Up @@ -3,3 +3,5 @@ build
dataplugin_tests/*/*.so
dataplugin_tests/hello/hello
dataplugin_tests/wchar_t/wchar
dataplugin_tests/std_str/stdstr

14 changes: 14 additions & 0 deletions dataplugin_tests/std_str/Makefile
@@ -0,0 +1,14 @@
all: viewstdstr.so stdstr

.PHONY: clean
clean:
rm -f stdstr viewstdstr.so

stdstr: stdstr.cpp
g++ -o stdstr -Wall -O0 -g stdstr.cpp

viewstdstr.so: viewstdstr.cpp
g++ -o viewstdstr.so -shared -fPIC -Wall -O0 -g viewstdstr.cpp -I../../src/gdb

# end of Makefile ...

12 changes: 12 additions & 0 deletions dataplugin_tests/std_str/stdstr.cpp
@@ -0,0 +1,12 @@
#include <string>

int main(void)
{
std::string x("Hello, world!");
std::string y("blah blah blah");
return (strlen(x.c_str()) != strlen(y.c_str())) ? 0 : 1;
}

/* end of viewstdstr.cpp ... */


50 changes: 50 additions & 0 deletions dataplugin_tests/std_str/viewstdstr.cpp
@@ -0,0 +1,50 @@
#include <string>
#include <wchar.h>
#include "gdb-dataplugins.h"

static void view_std_string(const void *ptr, const GDB_dataplugin_funcs *funcs)
{
char buf[sizeof (std::string)]; // we don't actually want to construct.

if (funcs->readmem(ptr, buf, sizeof (buf)) != 0)
return;

// the c_str() call only works if it doesn't want to touch anything we
// haven't read from the target process, but it's easier than dealing
// with private fields.
const std::string *stdstr = (const std::string *) buf;
char *cstr = (char *) funcs->readstr(stdstr->c_str(), sizeof (char));
if (cstr == 0)
return;

funcs->print("(const char *) \"%s\"\n", cstr);
funcs->freemem(cstr);
}

static void view_std_wstring(const void *ptr, const GDB_dataplugin_funcs *funcs)
{
char buf[sizeof (std::wstring)]; // we don't actually want to construct.

if (funcs->readmem(ptr, buf, sizeof (buf)) != 0)
return;

const std::wstring *stdwstr = (const std::wstring *) buf;
wchar_t *wcstr = (wchar_t *) funcs->readstr(stdwstr->c_str(), sizeof (wchar_t));
if (wcstr == 0)
return;

funcs->print("(const wchar_t *) \"%ls\"\n", wcstr);
funcs->freemem(wcstr);
}

void GDB_DATAPLUGIN_ENTRY(const GDB_dataplugin_entry_funcs *funcs)
{
funcs->register_viewer("std::string", view_std_string);
funcs->register_viewer("std::wstring", view_std_wstring);
funcs->register_viewer("string", view_std_string);
funcs->register_viewer("wstring", view_std_wstring);
}

/* end of viewstdstr.cpp ... */


0 comments on commit 42e33be

Please sign in to comment.