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

Commit

Permalink
Added getsize callback, and added our -fshort-wchar example back in.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 7, 2008
1 parent accacf3 commit 1ff0284
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .hgignore
Expand Up @@ -2,6 +2,7 @@ syntax:glob
build
dataplugin_tests/*/*.so
dataplugin_tests/hello/hello
dataplugin_tests/wchar_t/wchar
dataplugin_tests/wchar_t/wchar32
dataplugin_tests/wchar_t/wchar16
dataplugin_tests/std_str/stdstr

11 changes: 7 additions & 4 deletions dataplugin_tests/wchar_t/Makefile
@@ -1,11 +1,14 @@
all: viewwchar.so wchar
all: viewwchar.so wchar32 wchar16

.PHONY: clean
clean:
rm -f wchar viewwchar.so
rm -f wchar32 wchar16 viewwchar.so

wchar: wchar.c
gcc -o wchar -Wall -O0 -g wchar.c
wchar32: wchar.c
gcc -o wchar32 -Wall -O0 -g wchar.c

wchar16: wchar.c
gcc -o wchar16 -Wall -O0 -g wchar.c -fshort-wchar

viewwchar.so: viewwchar.c
gcc -o viewwchar.so -shared -fPIC -Wall -O0 -g viewwchar.c -I../../src/gdb
Expand Down
31 changes: 18 additions & 13 deletions dataplugin_tests/wchar_t/viewwchar.c
Expand Up @@ -30,24 +30,29 @@ static void view_wchar_t_##bits(const void *ptr, const GDB_dataplugin_funcs *fun
funcs->freemem(str); \
}

//VIEW_WCHAR_T_IMPL(16)
VIEW_WCHAR_T_IMPL(32)
//VIEW_WCHAR_T_IMPL(64)
VIEW_WCHAR_T_IMPL(8) /* can this happen? */
VIEW_WCHAR_T_IMPL(16) /* -fshort-wchar, Windows UCS-2. */
VIEW_WCHAR_T_IMPL(32) /* Normal Unix UCS-4. */
VIEW_WCHAR_T_IMPL(64) /* still waiting for UCS-8. :) */

void GDB_DATAPLUGIN_ENTRY(const GDB_dataplugin_entry_funcs *funcs)
{
// size_t size = 0;
// if (!funcs->get_type_geometry("wchar_t", &size, NULL))
// return;
size_t size = 0;
if (funcs->getsize("wchar_t", &size) == -1)
return;

// if (size == 2)
// funcs->register_viewer("wchar_t *", view_wchar_t_16);
// else if (size == 4)
funcs->warning("sizeof (wchar_t) is %d", (int) size);

if (size == 1)
funcs->register_viewer("wchar_t *", view_wchar_t_8);
else if (size == 2)
funcs->register_viewer("wchar_t *", view_wchar_t_16);
else if (size == 4)
funcs->register_viewer("wchar_t *", view_wchar_t_32);
// else if (size == 8)
// funcs->register_viewer("wchar_t *", view_wchar_t_64);
// else
// funcs->warning("sizeof (wchar_t) is %d ... we only handle 2, 4, 8.");
else if (size == 8)
funcs->register_viewer("wchar_t *", view_wchar_t_64);
else
funcs->warning("sizeof (wchar_t) is %d ... we only handle 1, 2, 4, 8.", (int) size);
}

/* end of viewwchar.c ... */
Expand Down
2 changes: 1 addition & 1 deletion dataplugin_tests/wchar_t/wchar.c
Expand Up @@ -4,6 +4,6 @@ int main(void)
{
wchar_t *x = L"Hello, world!";
wchar_t *y = L"blah blah blah";
return (wcslen(x) != wcslen(y)) ? 0 : 1;
return (x != y) ? 0 : 1;
}

5 changes: 5 additions & 0 deletions src/gdb/gdb-dataplugins.h
Expand Up @@ -56,10 +56,14 @@ typedef void (*GDB_dataplugin_freefn)(void *ptr);
/* callback for reporting a problem inside a data plugin. warning(). */
typedef void (*GDB_dataplugin_warning)(const char *, ...);

/* callback for querying a data type's size. */
typedef int (*GDB_dataplugin_get_size)(const char *, unsigned long *);

typedef struct
{
GDB_dataplugin_warning warning;
GDB_dataplugin_printfn print;
GDB_dataplugin_get_size getsize;
GDB_dataplugin_readmemfn readmem;
GDB_dataplugin_readstrfn readstr;
GDB_dataplugin_mallocfn allocmem;
Expand All @@ -76,6 +80,7 @@ typedef void (*GDB_dataplugin_register)(const char *, GDB_dataplugin_viewfn);
typedef struct
{
GDB_dataplugin_warning warning;
GDB_dataplugin_get_size getsize;
GDB_dataplugin_mallocfn allocmem;
GDB_dataplugin_reallocfn reallocmem;
GDB_dataplugin_freefn freemem;
Expand Down
37 changes: 37 additions & 0 deletions src/gdb/printcmd.c
Expand Up @@ -178,6 +178,41 @@ static void do_one_display (struct display *);
/* !!! FIXME: need a way to delete the hash at shutdown. just atexit()? */
static htab_t dataplugin_htab = 0;

static int
dataplugin_get_size(const char *_exp, unsigned long *size)
{
int retval = -1;

if (!_exp)
warning(_("Data plugin passed a NULL expression to get_size()"));
else if (!size)
warning(_("Data plugin passed a NULL size pointer to get_size()"));
else
{
char *exp = xstrdup(_exp); /* so we're not const... */
struct expression *expr = parse_expression (exp);
struct cleanup *old_chain = make_cleanup (free_current_contents, &expr);
struct value *value = evaluate_type (expr);
if (value == NULL)
warning(_("Data plugin couldn't parse expression '%s'"), exp);
else
{
struct type *type = value_type (value);
if (type == NULL)
warning(_("Data plugin couldn't find type '%s' for get_size()"), exp);
else
{
*size = TYPE_LENGTH (type);
retval = 0; /* success! */
}
}
do_cleanups (old_chain);
xfree(exp);
}

return retval;
}

static int
dataplugin_read_memory(const void *src, void *dst, int len)
{
Expand Down Expand Up @@ -289,6 +324,7 @@ static const GDB_dataplugin_funcs dataplugin_funcs =
{
warning,
printf_unfiltered,
dataplugin_get_size,
dataplugin_read_memory,
dataplugin_read_string,
dataplugin_alloc_memory,
Expand All @@ -299,6 +335,7 @@ static const GDB_dataplugin_funcs dataplugin_funcs =
static const GDB_dataplugin_entry_funcs dataplugin_entry_funcs =
{
warning,
dataplugin_get_size,
dataplugin_alloc_memory,
dataplugin_realloc_memory,
dataplugin_free_memory,
Expand Down

0 comments on commit 1ff0284

Please sign in to comment.