diff options
author | Andrew Cagney <cagney@redhat.com> | 2001-10-17 20:35:31 +0000 |
---|---|---|
committer | Andrew Cagney <cagney@redhat.com> | 2001-10-17 20:35:31 +0000 |
commit | 03dd37c302866305fa6d48988f558c4eba2bbabe (patch) | |
tree | 49872886cd0a94c86515feeb01c0ba6e9eeb8495 | |
parent | 4058e45f546df4f7e887ea2c6ec4fb7f2ab3b1d7 (diff) | |
download | gdb-03dd37c302866305fa6d48988f558c4eba2bbabe.zip gdb-03dd37c302866305fa6d48988f558c4eba2bbabe.tar.gz gdb-03dd37c302866305fa6d48988f558c4eba2bbabe.tar.bz2 |
Functions to convert to/from CORE_ADDR and a string. Use in Insight.
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/defs.h | 6 | ||||
-rw-r--r-- | gdb/utils.c | 44 |
3 files changed, 60 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index aea9dc1..1cc56a5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2001-10-16 Andrew Cagney <ac131313@redhat.com> + + Based on code by John Moore <jmore@redhat.com>: + + * utils.c (core_addr_to_string): New function for conversion of + CORE_ADDR to string. + (string_to_core_addr): New function to convert from string to + CORE_ADDR. + * defs.h: Added extern statements for the above. + 2001-10-17 Jason Molenda (jason-cl@molenda.com) * symtab.c (lookup_block_symbol): Break out of linear search @@ -690,6 +690,12 @@ extern char *paddr_d (LONGEST addr); extern char *phex (ULONGEST l, int sizeof_l); extern char *phex_nz (ULONGEST l, int sizeof_l); +/* Like paddr() only print/scan raw CORE_ADDR. The output from + core_addr_to_string() can be passed direct to + string_to_core_addr(). */ +extern const char *core_addr_to_string (const CORE_ADDR addr); +extern CORE_ADDR string_to_core_addr (const char *my_string); + extern void fprintf_symbol_filtered (struct ui_file *, char *, enum language, int); diff --git a/gdb/utils.c b/gdb/utils.c index ba73d8d..d32957f 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2490,3 +2490,47 @@ address_to_host_pointer (CORE_ADDR addr) ADDRESS_TO_POINTER (builtin_type_void_data_ptr, &ptr, addr); return ptr; } + +/* Convert a CORE_ADDR into a string. */ +const char * +core_addr_to_string (const CORE_ADDR addr) +{ + char *str = get_cell (); + strcpy (str, "0x"); + strcat (str, phex_nz (addr, sizeof (addr))); + return str; +} + +/* Convert a string back into a CORE_ADDR. */ +CORE_ADDR +string_to_core_addr (const char *my_string) +{ + CORE_ADDR addr = 0; + if (my_string[0] == '0' && tolower (my_string[1]) == 'x') + { + /* Assume that it is in decimal. */ + int i; + for (i = 2; my_string[i] != '\0'; i++) + { + if (isdigit (my_string[i])) + addr = (my_string[i] - '0') + (addr * 16); + else if (isxdigit (my_string[i])) + addr = (tolower (my_string[i]) - 'a' + 0xa) + (addr * 16); + else + internal_error (__FILE__, __LINE__, "invalid hex"); + } + } + else + { + /* Assume that it is in decimal. */ + int i; + for (i = 0; my_string[i] != '\0'; i++) + { + if (isdigit (my_string[i])) + addr = (my_string[i] - '0') + (addr * 10); + else + internal_error (__FILE__, __LINE__, "invalid decimal"); + } + } + return addr; +} |