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 /gdb/utils.c | |
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.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 44 |
1 files changed, 44 insertions, 0 deletions
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; +} |