Functions to convert to/from CORE_ADDR and a string. Use in Insight.

This commit is contained in:
Andrew Cagney 2001-10-17 20:35:31 +00:00
parent 4058e45f54
commit 03dd37c302
3 changed files with 60 additions and 0 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;
}