Discussion:
Disassembling ARM and Thumb code
Shaun Jackman
2005-05-06 00:05:56 UTC
Permalink
My ARM7TDMI processor is currently in Thumb mode, but the x/i command
dissects the instruction as an ARM instruction. The symbol
rdp_getargvsp is a Thumb symbol added using add-symbol-file [elf
binary here]. What is the command to disassemble a given memory
location as a Thumb instruction?

Thanks,
Shaun

(gdb) p/x $cpsr
$10 = 0x4000003f
(gdb) x/i $pc
0x20004dc <rdp_getargvsp>: cmpcs r4, #67108864 ; 0x4000000
(gdb)
0x20004e0 <rdp_getargvsp+4>: strmibt r2, [r9], -r0, lsl #8

$ arm-elf-gdb --version
GNU gdb 6.2.1
...
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-elf".
Daniel Jacobowitz
2005-05-06 01:55:59 UTC
Permalink
Post by Shaun Jackman
My ARM7TDMI processor is currently in Thumb mode, but the x/i command
dissects the instruction as an ARM instruction. The symbol
rdp_getargvsp is a Thumb symbol added using add-symbol-file [elf
binary here]. What is the command to disassemble a given memory
location as a Thumb instruction?
How is it marked as Thumb in the binary?

GDB does not use the current CPSR value when disassembling; that way
lies madness.
--
Daniel Jacobowitz
CodeSourcery, LLC
Shaun Jackman
2005-05-06 03:35:02 UTC
Permalink
Post by Daniel Jacobowitz
Post by Shaun Jackman
My ARM7TDMI processor is currently in Thumb mode, but the x/i command
dissects the instruction as an ARM instruction. The symbol
rdp_getargvsp is a Thumb symbol added using add-symbol-file [elf
binary here]. What is the command to disassemble a given memory
location as a Thumb instruction?
How is it marked as Thumb in the binary?
It's marked with a $t symbol at the same address.

$ nm busybox | grep 020004dd
020004dd t $t
020004dd t rdp_getargvsp

I haven't read this in documentation; only noticed it from empirical
evidence. For example, here's a symbol compiled for ARM marked with a
$a symbol at the same address.

$ nm hello | grep 000081f8
000081f8 t $a
000081f8 T main
Post by Daniel Jacobowitz
GDB does not use the current CPSR value when disassembling; that way
lies madness.
Hehe. I agree, that's probably not the best plan. However, for the
unique case of 'x/i $pc' it does make a certain amount of sense to use
the CPSR as a hint. I'm not sure if it's worth the special case
though. An explicit switch to the x/i and disas commands to specify
ARM or Thumb dissection is very much a good idea though.

Cheers,
Shaun
Daniel Jacobowitz
2005-05-06 04:07:55 UTC
Permalink
Post by Shaun Jackman
Post by Daniel Jacobowitz
Post by Shaun Jackman
My ARM7TDMI processor is currently in Thumb mode, but the x/i command
dissects the instruction as an ARM instruction. The symbol
rdp_getargvsp is a Thumb symbol added using add-symbol-file [elf
binary here]. What is the command to disassemble a given memory
location as a Thumb instruction?
How is it marked as Thumb in the binary?
It's marked with a $t symbol at the same address.
$ nm busybox | grep 020004dd
020004dd t $t
020004dd t rdp_getargvsp
I haven't read this in documentation; only noticed it from empirical
evidence. For example, here's a symbol compiled for ARM marked with a
$a symbol at the same address.
$ nm hello | grep 000081f8
000081f8 t $a
000081f8 T main
GDB doesn't understand ARM mapping symbols. It could, with some
work, but it doesn't yet. However it should understand the odd symbol
address. If that's not working, there's a bug somewhere.
Post by Shaun Jackman
Hehe. I agree, that's probably not the best plan. However, for the
unique case of 'x/i $pc' it does make a certain amount of sense to use
the CPSR as a hint. I'm not sure if it's worth the special case
though. An explicit switch to the x/i and disas commands to specify
ARM or Thumb dissection is very much a good idea though.
Yes, probably; if you have a good idea for the syntax to use, then
maybe we can add it. I don't much like the idea of target-specific
modifiers.
--
Daniel Jacobowitz
CodeSourcery, LLC
Shaun Jackman
2005-05-06 16:35:10 UTC
Permalink
Post by Daniel Jacobowitz
Post by Shaun Jackman
Hehe. I agree, that's probably not the best plan. However, for the
unique case of 'x/i $pc' it does make a certain amount of sense to use
the CPSR as a hint. I'm not sure if it's worth the special case
though. An explicit switch to the x/i and disas commands to specify
ARM or Thumb dissection is very much a good idea though.
Yes, probably; if you have a good idea for the syntax to use, then
maybe we can add it. I don't much like the idea of target-specific
modifiers.
I like the look of this:

x/i for intelligent
x/iw for ARM
x/ih for Thumb

Another option is...

set disassembly-flavor arm
set disassembly-flavor thumb

Cheers,
Shaun
Richard Earnshaw
2005-05-09 12:47:58 UTC
Permalink
Post by Shaun Jackman
Post by Daniel Jacobowitz
Post by Shaun Jackman
Hehe. I agree, that's probably not the best plan. However, for the
unique case of 'x/i $pc' it does make a certain amount of sense to use
the CPSR as a hint. I'm not sure if it's worth the special case
though. An explicit switch to the x/i and disas commands to specify
ARM or Thumb dissection is very much a good idea though.
Yes, probably; if you have a good idea for the syntax to use, then
maybe we can add it. I don't much like the idea of target-specific
modifiers.
x/i for intelligent
x/iw for ARM
x/ih for Thumb
Ug. Doesn't really make sense for Thumb-2. Nor does it make sense for
the 'disassemble' command.
Post by Shaun Jackman
Another option is...
set disassembly-flavor arm
set disassembly-flavor thumb
less objectionable, provided you avoid 'flavor' which is irritating to
those who use British English spelling.

I'd go for

set disassembly-isa {auto|arm|thumb}

R.
Shaun Jackman
2005-05-09 16:07:03 UTC
Permalink
Post by Richard Earnshaw
Post by Shaun Jackman
x/i for intelligent
x/iw for ARM
x/ih for Thumb
Ug. Doesn't really make sense for Thumb-2. Nor does it make sense for
the 'disassemble' command.
x/ia for ARM/Thumb-2 and x/it for Thumb then. Even with a 'set ...
{arm, thumb}' command, a quick-to-type and
quick-override-of-the-default x/i style command is useful.
Post by Richard Earnshaw
Post by Shaun Jackman
Another option is...
set disassembly-flavor arm
set disassembly-flavor thumb
less objectionable, provided you avoid 'flavor' which is irritating to
those who use British English spelling.
I'd go for
set disassembly-isa {auto|arm|thumb}
R.
I agree entirely, but I'd guess that disassembly-flavor has been
around for a while. Should the previous spelling be deprecated?

objdump already has a name for this option:
set disassembler-options {intel, att, force-thumb, ...}
I'd prefer simply `thumb' to `force-thumb', but parallelism between
tools is a healthy goal.

Cheers,
Shaun

Continue reading on narkive:
Loading...