From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1056 invoked by alias); 24 Mar 2004 23:51:31 -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 1022 invoked from network); 24 Mar 2004 23:51:26 -0000 Received: from unknown (HELO takamaka.act-europe.fr) (142.179.108.108) by sources.redhat.com with SMTP; 24 Mar 2004 23:51:26 -0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 0F56147D62; Wed, 24 Mar 2004 15:51:26 -0800 (PST) Date: Wed, 24 Mar 2004 23:51:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: [RFA/amd64] Pb with parameter passing in inferior function call Message-ID: <20040324235125.GK5083@gnat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy" Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2004-03/txt/msg00580.txt.bz2 --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2416 Hello, A collegue of mine recently complained that inferior function calls on amd64 where often leading to a SIGSEGV in the inferior. Most notably, he was trying to call a function in GCC that, given a node ID (a simple number), prints everything about that node. Once I understood the source of the problem, I was able to reproduce it with a much smaller example. Unfortunately, it has to be in Ada, because it involves range types. Here is the code: << package Pck is type Node_Id is new Integer range 0 .. Integer'Last; procedure Print_Node (N : Node_Id); end Pck; with Ada.Text_IO; use Ada.Text_IO; package body Pck is procedure Pn (N: Node_Id); pragma Export (C, Pn, "pn"); -- Another wrapper around Print_Node exported via "pragma Export C" -- to allow us to easily call it from a C debugger. ---------------- -- Print_Node -- ---------------- procedure Print_Node (N : Node_Id) is begin Put_Line ("Node:" & Node_Id'Image (N)); end Print_Node; -------- -- Pn -- -------- procedure Pn (N: Node_Id) is begin Print_Node (N); end Pn; end Pck; with Pck; use Pck; procedure Foo is begin Print_Node (1); end Foo; >> Compile it using the following command: % gnatmake -g foo The debug it with GDB (doesn't have to be an Ada-aware debugger): (gdb) list foo.adb:1 1 with Pck; use Pck; 2 3 procedure Foo is 4 begin 5 Print_Node (1); 6 end Foo; (gdb) b foo.adb:5 Breakpoint 1 at 0x4024f4: file foo.adb, line 5. (gdb) run Starting program: /don.a/brobecke/calling_pb/foo Breakpoint 1, _ada_foo () at foo.adb:5 5 Print_Node (1); Current language: auto; currently minimal (gdb) call pn (1234) !!! -> Node:-1786175552 The last line is incorrect. The node ID should be 1234. The problem is that type Node_Id is a 4 bytes range type. Procedure "Pn" expects this parameter to be passed via %rdi. But there is a slight omission in amd64_classify that does not classifies RANGE_TYPE entities in the INTEGER class. The attached patch fixes this. 2004-02-24 J. Brobecker * amd64-tdep.c (amd64_classify): make RANGE_TYPE objects be part of the INTEGER class. Tested on amd64-linux. No regression. Ok to apply? Thanks, -- Joel --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="amd64.diff" Content-length: 923 Index: amd64-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/amd64-tdep.c,v retrieving revision 1.5 diff -u -p -r1.5 amd64-tdep.c --- amd64-tdep.c 23 Mar 2004 14:47:55 -0000 1.5 +++ amd64-tdep.c 24 Mar 2004 19:12:57 -0000 @@ -371,8 +371,11 @@ amd64_classify (struct type *type, enum class[0] = class[1] = AMD64_NO_CLASS; /* Arguments of types (signed and unsigned) _Bool, char, short, int, - long, long long, and pointers are in the INTEGER class. */ + long, long long, and pointers are in the INTEGER class. Similarly, + range types, used by languages such as Ada, are also in the INTEGER + class. */ if ((code == TYPE_CODE_INT || code == TYPE_CODE_ENUM + || code == TYPE_CODE_RANGE || code == TYPE_CODE_PTR || code == TYPE_CODE_REF) && (len == 1 || len == 2 || len == 4 || len == 8)) class[0] = AMD64_INTEGER; --KsGdsel6WgEHnImy--