This repository has been archived by the owner on Jul 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ... */ | ||
|
||
|