[RFA/amd64] Pb with parameter passing in inferior function call
Joel Brobecker
brobecker@gnat.com
Wed Mar 24 23:51:00 GMT 2004
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 <brobecker@gnat.com>
* 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
-------------- next part --------------
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;
More information about the Gdb-patches
mailing list