This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/amd64] Pb with parameter passing in inferior function call


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

Attachment: amd64.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]