aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>2003-05-01 23:21:08 +0000
committerAndrew Cagney <cagney@redhat.com>2003-05-01 23:21:08 +0000
commit2b6fd0d87d374675c1cba32ce24cf5c34870d956 (patch)
treed28b9349d909b93bea920879f580b1509332dddd
parent13e10c0a01bb77b60670a217609241b554f82349 (diff)
downloadgdb-2b6fd0d87d374675c1cba32ce24cf5c34870d956.zip
gdb-2b6fd0d87d374675c1cba32ce24cf5c34870d956.tar.gz
gdb-2b6fd0d87d374675c1cba32ce24cf5c34870d956.tar.bz2
2003-05-01 Andrew Cagney <cagney@redhat.com>
* disasm.c (gdb_disassemble_from_exec): Delete global variable. (gdb_disassembly): Make "di" non static, always initialize and cleanup. Always use dis_asm_read_memory. (gdb_dis_asm_read_memory): Delete function. 2003-05-01 Andrew Cagney <cagney@redhat.com> * gdb.asm/asm-source.exp: Check that "disassm" and "x/i" of a variable do not give memory errors.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/disasm.c89
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.asm/asm-source.exp28
4 files changed, 56 insertions, 73 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e9221f7..d6635c7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2003-05-01 Andrew Cagney <cagney@redhat.com>
+ * disasm.c (gdb_disassemble_from_exec): Delete global variable.
+ (gdb_disassembly): Make "di" non static, always initialize and
+ cleanup. Always use dis_asm_read_memory.
+ (gdb_dis_asm_read_memory): Delete function.
+
+2003-05-01 Andrew Cagney <cagney@redhat.com>
+
* d10v-tdep.c (d10v_frame_align): Replace d10v_stack_align.
(d10v_gdbarch_init): Set frame_align instead of stack_align.
diff --git a/gdb/disasm.c b/gdb/disasm.c
index e460255..44ad545 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -65,29 +65,6 @@ dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
print_address (addr, info->stream);
}
-/* This variable determines where memory used for disassembly is read from. */
-int gdb_disassemble_from_exec = -1;
-
-/* This is the memory_read_func for gdb_disassemble when we are
- disassembling from the exec file. */
-static int
-gdb_dis_asm_read_memory (bfd_vma memaddr, bfd_byte * myaddr,
- unsigned int len, disassemble_info * info)
-{
- extern struct target_ops exec_ops;
- int res;
-
- errno = 0;
- res = xfer_memory (memaddr, myaddr, len, 0, 0, &exec_ops);
-
- if (res == len)
- return 0;
- else if (errno == 0)
- return EIO;
- else
- return errno;
-}
-
static int
compare_lines (const void *mle1p, const void *mle2p)
{
@@ -337,62 +314,31 @@ gdb_disassembly (struct ui_out *uiout,
int mixed_source_and_assembly,
int how_many, CORE_ADDR low, CORE_ADDR high)
{
- static disassemble_info di;
- static int di_initialized;
+ struct ui_stream *stb = ui_out_stream_new (uiout);
+ struct cleanup *cleanups = make_cleanup_ui_out_stream_delete (stb);
+ disassemble_info di;
/* To collect the instruction outputted from opcodes. */
- static struct ui_stream *stb = NULL;
struct symtab *symtab = NULL;
struct linetable_entry *le = NULL;
int nlines = -1;
- if (!di_initialized)
- {
- /* We don't add a cleanup for this, because the allocation of
- the stream is done once only for each gdb run, and we need to
- keep it around until the end. Hopefully there won't be any
- errors in the init code below, that make this function bail
- out. */
- stb = ui_out_stream_new (uiout);
- INIT_DISASSEMBLE_INFO_NO_ARCH (di, stb->stream,
- (fprintf_ftype) fprintf_unfiltered);
- di.flavour = bfd_target_unknown_flavour;
- di.memory_error_func = dis_asm_memory_error;
- di.print_address_func = dis_asm_print_address;
- di_initialized = 1;
- }
-
+ INIT_DISASSEMBLE_INFO_NO_ARCH (di, stb->stream,
+ (fprintf_ftype) fprintf_unfiltered);
+ di.flavour = bfd_target_unknown_flavour;
+ di.memory_error_func = dis_asm_memory_error;
+ di.print_address_func = dis_asm_print_address;
+ /* NOTE: cagney/2003-04-28: The original code, from the old Insight
+ disassembler had a local optomization here. By default it would
+ access the executable file, instead of the target memory (there
+ was a growing list of exceptions though). Unfortunatly, the
+ heuristic was flawed. Commands like "disassemble &variable"
+ didn't work as they relied on the access going to the target.
+ Further, it has been supperseeded by trust-read-only-sections
+ (although that should be superseeded by target_trust..._p()). */
+ di.read_memory_func = dis_asm_read_memory;
di.mach = gdbarch_bfd_arch_info (current_gdbarch)->mach;
di.endian = gdbarch_byte_order (current_gdbarch);
- /* If gdb_disassemble_from_exec == -1, then we use the following heuristic to
- determine whether or not to do disassembly from target memory or from the
- exec file:
-
- If we're debugging a local process, read target memory, instead of the
- exec file. This makes disassembly of functions in shared libs work
- correctly. Also, read target memory if we are debugging native threads.
-
- Else, we're debugging a remote process, and should disassemble from the
- exec file for speed. However, this is no good if the target modifies its
- code (for relocation, or whatever). */
-
- if (gdb_disassemble_from_exec == -1)
- {
- if (strcmp (target_shortname, "child") == 0
- || strcmp (target_shortname, "procfs") == 0
- || strcmp (target_shortname, "vxprocess") == 0
- || strcmp (target_shortname, "core") == 0
- || strstr (target_shortname, "-thread") != NULL)
- gdb_disassemble_from_exec = 0; /* It's a child process, read inferior mem */
- else
- gdb_disassemble_from_exec = 1; /* It's remote, read the exec file */
- }
-
- if (gdb_disassemble_from_exec)
- di.read_memory_func = gdb_dis_asm_read_memory;
- else
- di.read_memory_func = dis_asm_read_memory;
-
/* Assume symtab is valid for whole PC range */
symtab = find_pc_symtab (low);
@@ -411,6 +357,7 @@ gdb_disassembly (struct ui_out *uiout,
do_mixed_source_and_assembly (uiout, &di, nlines, le, low,
high, symtab, how_many, stb);
+ do_cleanups (cleanups);
gdb_flush (gdb_stdout);
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index edecb73..6dc760e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2003-05-01 Andrew Cagney <cagney@redhat.com>
+
+ * gdb.asm/asm-source.exp: Check that "disassm" and "x/i" of a
+ variable do not give memory errors.
+
2003-04-30 Adam Fedor <fedor@gnu.org>
* Makefile.in (ALL_SUBDIRS): Add gdb.objc
diff --git a/gdb/testsuite/gdb.asm/asm-source.exp b/gdb/testsuite/gdb.asm/asm-source.exp
index ac1bcd2..96b7991 100644
--- a/gdb/testsuite/gdb.asm/asm-source.exp
+++ b/gdb/testsuite/gdb.asm/asm-source.exp
@@ -293,11 +293,35 @@ gdb_test "next" "17\[ \t\]+gdbasm_leave" "next over foo3"
gdb_test "return" "\#0 main .*37\[ \t\]+gdbasm_exit0" "return from foo2" \
"Make (foo2|selected stack frame) return now\?.*" "y"
-# See if we can look at a global variable
+# Disassemble something, check the output
+proc test_dis { command var } {
+ global gdb_prompt
+ send_gdb "${command}\n"
+ gdb_expect {
+ -re "${var}.*:.*Cannot access" {
+ # The "disassembler" was only accessing the local
+ # executable and that would cause attempts to disassemble
+ # variables to fail (memory not valid).
+ fail "${command} (memory read error)"
+ }
+ -re "${var}.*:.*${gdb_prompt}" {
+ pass "${command}"
+ }
+ timeout {
+ fail "${command} (timeout)"
+ }
+ }
+}
+
+# See if we can look at a global variable, three ways
gdb_test "print globalvar" ".* = 11" "look at global variable"
+test_dis "x/i globalvar" "globalvar"
+test_dis "disassem &globalvar &globalvar+1" "globalvar"
-# See if we can look at a static variable
+# See if we can look at a static variable, three ways
gdb_test "print staticvar" ".* = 5" "look at static variable"
+test_dis "x/i &staticvar" "staticvar"
+test_dis "disassem &staticvar &staticvar+1" "staticvar"
# See if we can look at a static function
gdb_test "disassem foostatic" ".*<foostatic\\+0>:.*End of assembler dump." \