From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14493 invoked by alias); 4 Jul 2002 22:02:50 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 14345 invoked from network); 4 Jul 2002 22:02:45 -0000 Received: from unknown (HELO walton.kettenis.dyndns.org) (213.93.114.42) by sources.redhat.com with SMTP; 4 Jul 2002 22:02:45 -0000 Received: from elgar.kettenis.dyndns.org (elgar.kettenis.dyndns.org [192.168.0.2]) by walton.kettenis.dyndns.org (8.11.6/8.11.6) with ESMTP id g64M2ix01672; Fri, 5 Jul 2002 00:02:44 +0200 (CEST) (envelope-from kettenis@elgar.kettenis.dyndns.org) Received: (from kettenis@localhost) by elgar.kettenis.dyndns.org (8.11.6/8.11.6) id g64M2hT62589; Fri, 5 Jul 2002 00:02:43 +0200 (CEST) (envelope-from kettenis) Date: Thu, 04 Jul 2002 16:00:00 -0000 From: Mark Kettenis Message-Id: <200207042202.g64M2hT62589@elgar.kettenis.dyndns.org> To: gdb@sources.redhat.com CC: gdb-patches@sources.redhat.com Subject: [RFC] Implementation of DW_OP_deref and DW_OP_deref_size operators X-SW-Source: 2002-07/txt/msg00091.txt.bz2 After staring for a while at some compiler warnings resulting from an attempt to make an i386 x x86-64 cross-debugger, and failing to understand the code that implements the DW_OP_deref and DW_OP_deref_size operators I think I've found out what's wrong. These expressions are supposed to dereference pointers. In GDB this means that they should look at the address indicated by the pointer they're dereferencing *in the target*. The current code is trying to dereference a pointer in GDB. If we look at the history of this code it is perfectly understandable. It is largely copied from the unwinder that comes with GCC. This unwinder is supposed to be linked into the program that contains the DWARF2 code, so in that context it makes sense to lookup pointers in the program this code is running in. Does this sound reasonable? To fix this, I propose the following patch. Ok, to check this in? Mark Index: ChangeLog from Mark Kettenis * dwarf2cfi.c (execute_stack_op): Fix implementation of the DW_OP_deref and DW_OP_deref_size operators by letting do their lookup in the target. Index: dwarf2cfi.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2cfi.c,v retrieving revision 1.12 diff -u -p -r1.12 dwarf2cfi.c --- dwarf2cfi.c 4 Jul 2002 14:43:51 -0000 1.12 +++ dwarf2cfi.c 4 Jul 2002 21:50:39 -0000 @@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA. */ #include "defs.h" +#include "gdbcore.h" #include "symtab.h" #include "symfile.h" #include "objfiles.h" @@ -1119,32 +1120,21 @@ execute_stack_op (struct objfile *objfil { case DW_OP_deref: { - char *ptr = (char *) result; - result = read_pointer (objfile->obfd, &ptr); + int len = TARGET_ADDR_BIT / TARGET_CHAR_BIT; + if (len != 4 && len != 8) + internal_error (__FILE__, __LINE__, + "execute_stack_op error"); + result = read_memory_unsigned_integer (result, len); } break; case DW_OP_deref_size: { - char *ptr = (char *) result; - switch (*op_ptr++) - { - case 1: - result = read_1u (objfile->obfd, &ptr); - break; - case 2: - result = read_2u (objfile->obfd, &ptr); - break; - case 4: - result = read_4u (objfile->obfd, &ptr); - break; - case 8: - result = read_8u (objfile->obfd, &ptr); - break; - default: - internal_error (__FILE__, __LINE__, - "execute_stack_op error"); - } + int len = *op_ptr++; + if (len != 1 && len != 2 && len != 4 && len !=8) + internal_error (__FILE__, __LINE__, + "execute_stack_op error"); + result = read_memory_unsigned_integer (result, len); } break;