This is the mail archive of the 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]

Re: Calling an Ada subprogram with complex parameters

I've    managed   to   work out how to make GDB treat an address as if
data there was of specific type and make a call accordingly.

(gdb) set ({Rec} 0xABCDEF00).a := false
(gdb) set ({Rec} 0xABCDEF00).b := 55
(gdb) call myProc({Rec} *0xABCDEF00))


j> Hi,

j> I'm trying to invoke from the GDB an Ada subprogram (say a procedure) which takes a
j> complex-type as a parameter. I'm struggling to work out how this can
j> be done.

j> Say I have a type

j>      type Rec is record
j>           a : Boolean;
j>           b : Integer;
j>      end record;

j> and a procedure, which takes a variable of this type as a parameter:

j>     procedure myProc( data : in Rec );

j> .
j> ----
j> Now, from the GDB I'd like to make a call like this:
j>      (gdb) call myProc( data => Rec'(a => true, b => 55) );

j> but  this  doesn't  work  since GDB does not seem to fully support accessing
j> attributes (section of the GDB manual). (means = aposthrophe
j> notation does not always work).

j> ----
j> Therefore I wanted to try something else. For example:

j>           (gdb) call myProc($myRec);

j> where  $myRec  is  a  convenience  variable  of  type  "Rec", but this
j> wouldn't  work  either  since  convenience  variable  resides in
j> gdb-specific memory  space, complex types seem to be passed by reference and myProc
j> cannot access memory address of $myRec.

j> Besides,  even if that worked, here is another problem: I  was  able
j> to  'force' $myRec to be of type 'Rec' only by assigning   it   to
j> another   variable  of type Rec
j>           (e.g.  (gdb) set  $myRec  := otherVariableOfTypeRec)
j> which is not ideal since otherVariableOfTypeRec is not always
j> available. (In fact, in most cases it won't be.)
j> ----

j> Another solution would be to have a specific memory address (since I
j> don't have any local variables available - the call to the procedure
j> is made almost without any context) set to a value of type Rec using type casting.
j> Which would be something like this:

j>       (gdb) p *0xABCDEF00 := something_here;
j>       (gdb) call myProc(Rec(*0xABCDEF00))

j> But the problem here is that the bytes occupied by "something_here"
j> have to be correctly set to what would variable of type Rec normally
j> occupy. Also "something_here" has to be a single expression. It cannot
j> be a record aggregate like for instance "(True, 55)" since obviously there is no
j> type associated with the 0xABCDEF00 memory address and GDB probably
j> doesn't know what to do with an aggregate notation. (BTW: Is there a
j> way to tell GDB to treat a memory address as if it was of a specific
j> type?)

j> When I try to run
j>      (gdb) call myProc(Rec(*0xABCDEF00))
j> just to see what happens... (*0xABCDEF00 set to whatever resides at
j> that address) I'm getting:
j>      Program received signal SIGILL, Illegal instruction.

j> I must mention here that I'm quite new to Ada so the solution to my
j> problem may be not by using a gdb feature, but by using and Ada
j> language feature... (e.g. appropriate casting).

j> Does anyone have any idea how I can solve this problem?

j> Many thanks,
j> Jan

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