[PATCH] Catch errors in value_get_print_value

Nick Roberts
2007-02-01T20:51:56Z

Currently when common_val_print throws an error from install_new_value it gets
caught in mi_execute_command and prints an MI error (^error,...) without
cleaning up. This patch catches the error in value_get_print_value so that GDB
can proceed normally. It could be adapted to output something like
"<error_reading_variable>" but I think the empty string works better.

To see what currently happens, compile:

#include <stdlib.h>

typedef struct {
float a;
float b;
} substruct;

struct substruct1 {
float a1;
substruct b1;
};

main () {

struct substruct1 *abc4 = NULL;
int i = 1;
}

-------------------
and run under GDB as follows:

~"Using host libthread_db library \"/lib/libthread_db.so.1\".\n"
(gdb)
start
&"start\n"
Breakpoint 1 at 0x8048365: file temp4.c, line 15.
Starting program: /home/nickrob/temp4
main () at temp4.c:15
15 struct substruct1 *abc4 = NULL;
^done
(gdb)
n
&"n\n"
16 int i = 1;
^done
(gdb)
-var-create - * abc4
^done,name="var1",numchild="2",type="struct substruct1 *"
(gdb)
-var-list-children --all-values var1
&"Cannot access memory at address 0x4\n"
^error,msg="Cannot access memory at address 0x4"
(gdb)
-var-list-children --all-values var1
&&"Duplicate variable object name\n"
^error,msg="Duplicate variable object name"
(gdb)

--
Nick http://www.inet.net.nz/~nickrob

2007-02-02 Nick Roberts <nickrob@snap.net.nz>

* varobj.c (value_get_print_value): Catch errors from
common_val_print.

*** varobj.c 02 Feb 2007 09:32:33 +1300 1.82
--- varobj.c 02 Feb 2007 09:48:59 +1300
*************** value_get_print_value (struct value *val
*** 1702,1707 ****
--- 1702,1708 ----
struct ui_file *stb;
struct cleanup *old_chain;
char *thevalue;
+ struct gdb_exception except;

if (value == NULL)
return NULL;
*************** value_get_print_value (struct value *val
*** 1709,1715 ****
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);

! common_val_print (value, stb, format_code[(int) format], 1, 0, 0);
thevalue = ui_file_xstrdup (stb, &dummy);

do_cleanups (old_chain);
--- 1710,1720 ----
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);

! TRY_CATCH (except, RETURN_MASK_ERROR)
! {
! common_val_print (value, stb, format_code[(int) format], 1, 0, 0);
! }
!
thevalue = ui_file_xstrdup (stb, &dummy);

do_cleanups (old_chain);