Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* mode processor mode switch
@ 2020-01-14 11:59 Jirka Koutný
  2020-01-16 14:52 ` Luis Machado
  0 siblings, 1 reply; 5+ messages in thread
From: Jirka Koutný @ 2020-01-14 11:59 UTC (permalink / raw)
  To: gdb

Hello,

I have a 32-bit elf executable which at some point switches to long mode
(kernel is 64-bit). Is there a way to tell gdb about the .code32/64
directives? Because expectedly the switch messes up disassembly and
stepping.

Thank you
Jirka


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: mode processor mode switch
  2020-01-14 11:59 mode processor mode switch Jirka Koutný
@ 2020-01-16 14:52 ` Luis Machado
  2020-01-16 18:52   ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Luis Machado @ 2020-01-16 14:52 UTC (permalink / raw)
  To: Jirka Koutný, gdb

Hi,

On 1/14/20 8:58 AM, Jirka Koutný wrote:
> Hello,
> 
> I have a 32-bit elf executable which at some point switches to long mode
> (kernel is 64-bit). Is there a way to tell gdb about the .code32/64
> directives? Because expectedly the switch messes up disassembly and
> stepping.
> 
> Thank you
> Jirka
> 

Unfortunately i don't think there is a good way to achieve this with the 
current implementation.

You could teach GDB about the quirks in the architecture, but it sounds 
better to have a more general solution.

I'm working on making this more flexible though, since i have a need to 
make the architecture information per-thread, at least the target 
description with the registers and types.

But no ETA yet.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: mode processor mode switch
  2020-01-16 14:52 ` Luis Machado
@ 2020-01-16 18:52   ` Pedro Alves
  2020-01-17 21:46     ` John Baldwin
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2020-01-16 18:52 UTC (permalink / raw)
  To: Luis Machado, Jirka Koutný, gdb

On 1/16/20 2:51 PM, Luis Machado wrote:
> Hi,
> 
> On 1/14/20 8:58 AM, Jirka Koutný wrote:
>> Hello,
>>
>> I have a 32-bit elf executable which at some point switches to long mode
>> (kernel is 64-bit). Is there a way to tell gdb about the .code32/64
>> directives? Because expectedly the switch messes up disassembly and
>> stepping.
>>
>> Thank you
>> Jirka
>>
> 
> Unfortunately i don't think there is a good way to achieve this with the current implementation.
> 
> You could teach GDB about the quirks in the architecture, but it sounds better to have a more general solution.
> 
> I'm working on making this more flexible though, since i have a need to make the architecture information per-thread, at least the target description with the registers and types.
> 

For x86-64 in particular, I think the ideal solution would be for
the remote target to always report the widest mode it supports,
which would be 64-bit, and then do the 32-bit/16-bit modes
presentation all on the gdb side (i.e., user-visible 32-bit on
top of 64-bit description).  Mode switching would not change the remote
target description.  This is unlike the current architecture where a
remote server reports a 32-bit description for a 32-bit process even
if the remote server is actually running on a 64-bit machine.

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: mode processor mode switch
  2020-01-16 18:52   ` Pedro Alves
@ 2020-01-17 21:46     ` John Baldwin
  2020-01-21 12:56       ` Jirka Koutný
  0 siblings, 1 reply; 5+ messages in thread
From: John Baldwin @ 2020-01-17 21:46 UTC (permalink / raw)
  To: Pedro Alves, Luis Machado, Jirka Koutný, gdb

On 1/16/20 10:52 AM, Pedro Alves wrote:
> On 1/16/20 2:51 PM, Luis Machado wrote:
>> Hi,
>>
>> On 1/14/20 8:58 AM, Jirka Koutný wrote:
>>> Hello,
>>>
>>> I have a 32-bit elf executable which at some point switches to long mode
>>> (kernel is 64-bit). Is there a way to tell gdb about the .code32/64
>>> directives? Because expectedly the switch messes up disassembly and
>>> stepping.
>>>
>>> Thank you
>>> Jirka
>>>
>>
>> Unfortunately i don't think there is a good way to achieve this with the current implementation.
>>
>> You could teach GDB about the quirks in the architecture, but it sounds better to have a more general solution.
>>
>> I'm working on making this more flexible though, since i have a need to make the architecture information per-thread, at least the target description with the registers and types.
>>
> 
> For x86-64 in particular, I think the ideal solution would be for
> the remote target to always report the widest mode it supports,
> which would be 64-bit, and then do the 32-bit/16-bit modes
> presentation all on the gdb side (i.e., user-visible 32-bit on
> top of 64-bit description).  Mode switching would not change the remote
> target description.  This is unlike the current architecture where a
> remote server reports a 32-bit description for a 32-bit process even
> if the remote server is actually running on a 64-bit machine.

I think this is the way to go, but you might still need some way to specify
the mode.  I'm not quite sure what qemu does, but for a gdb stub I've
worked on for bhyve (a KVM-like hypervisor in FreeBSD), it always reports
the architecture as 64-bits but checks various control registers when
resolving virtual addresses for the 'm' and 'M' protocol commands.

-- 
John Baldwin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: mode processor mode switch
  2020-01-17 21:46     ` John Baldwin
@ 2020-01-21 12:56       ` Jirka Koutný
  0 siblings, 0 replies; 5+ messages in thread
From: Jirka Koutný @ 2020-01-21 12:56 UTC (permalink / raw)
  To: John Baldwin; +Cc: Pedro Alves, Luis Machado, gdb

Erm hey guys, thanks for all your responses. I found out that it works if
instead of inline assembly I just make a separate .S file and compile with
'as -m32 -g' and then link with gcc.

fre. 17. jan. 2020 kl. 21:45 skrev John Baldwin <jhb@freebsd.org>:

> On 1/16/20 10:52 AM, Pedro Alves wrote:
> > On 1/16/20 2:51 PM, Luis Machado wrote:
> >> Hi,
> >>
> >> On 1/14/20 8:58 AM, Jirka Koutný wrote:
> >>> Hello,
> >>>
> >>> I have a 32-bit elf executable which at some point switches to long
> mode
> >>> (kernel is 64-bit). Is there a way to tell gdb about the .code32/64
> >>> directives? Because expectedly the switch messes up disassembly and
> >>> stepping.
> >>>
> >>> Thank you
> >>> Jirka
> >>>
> >>
> >> Unfortunately i don't think there is a good way to achieve this with
> the current implementation.
> >>
> >> You could teach GDB about the quirks in the architecture, but it sounds
> better to have a more general solution.
> >>
> >> I'm working on making this more flexible though, since i have a need to
> make the architecture information per-thread, at least the target
> description with the registers and types.
> >>
> >
> > For x86-64 in particular, I think the ideal solution would be for
> > the remote target to always report the widest mode it supports,
> > which would be 64-bit, and then do the 32-bit/16-bit modes
> > presentation all on the gdb side (i.e., user-visible 32-bit on
> > top of 64-bit description).  Mode switching would not change the remote
> > target description.  This is unlike the current architecture where a
> > remote server reports a 32-bit description for a 32-bit process even
> > if the remote server is actually running on a 64-bit machine.
>
> I think this is the way to go, but you might still need some way to specify
> the mode.  I'm not quite sure what qemu does, but for a gdb stub I've
> worked on for bhyve (a KVM-like hypervisor in FreeBSD), it always reports
> the architecture as 64-bits but checks various control registers when
> resolving virtual addresses for the 'm' and 'M' protocol commands.
>
> --
> John Baldwin
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-01-21 12:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 11:59 mode processor mode switch Jirka Koutný
2020-01-16 14:52 ` Luis Machado
2020-01-16 18:52   ` Pedro Alves
2020-01-17 21:46     ` John Baldwin
2020-01-21 12:56       ` Jirka Koutný

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox