public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Why does `disassemble` behave differently on Linux and Mac?
@ 2021-01-24 15:06 Peng Yu
  2021-01-24 15:31 ` Simon Marchi
  2021-01-24 15:35 ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Peng Yu @ 2021-01-24 15:06 UTC (permalink / raw)
  To: gdb

Hi,

https://visualgdb.com/gdbreference/commands/set_disassembly-flavor

I am trying to follow the above example, but it does behave the same
on Linux and Mac. Does anybody know how to make it work on Mac?
Thanks.

On Linux:

$ uname
Linux
$ cat func.c
int func(int a, int b) {
    return a + b;
}
$ gcc -c func.c
$ gdb -q func.o
Reading symbols from func.o...
(No debugging symbols found in func.o)
(gdb) show disassembly-flavor
The disassembly flavor is "att".
(gdb) disassemble func
Dump of assembler code for function func:
   0x0000000000000000 <+0>:	push   %rbp
   0x0000000000000001 <+1>:	mov    %rsp,%rbp
   0x0000000000000004 <+4>:	mov    %edi,-0x4(%rbp)
   0x0000000000000007 <+7>:	mov    %esi,-0x8(%rbp)
   0x000000000000000a <+10>:	mov    -0x4(%rbp),%edx
   0x000000000000000d <+13>:	mov    -0x8(%rbp),%eax
   0x0000000000000010 <+16>:	add    %edx,%eax
   0x0000000000000012 <+18>:	pop    %rbp
   0x0000000000000013 <+19>:	ret
End of assembler dump.

On Mac:

$ uname
Darwin
$ cat func.c
int func(int a, int b) {
    return a + b;
}
$ gcc -c func.c
$ gdb -q func.o
Reading symbols from func.o...
(No debugging symbols found in func.o)
(gdb) show disassembly-flavor
The disassembly flavor is "att".
(gdb) disassemble func
No symbol table is loaded.  Use the "file" command.

-- 
Regards,
Peng

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

* Re: Why does `disassemble` behave differently on Linux and Mac?
  2021-01-24 15:06 Why does `disassemble` behave differently on Linux and Mac? Peng Yu
@ 2021-01-24 15:31 ` Simon Marchi
  2021-01-24 15:35 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2021-01-24 15:31 UTC (permalink / raw)
  To: Peng Yu, gdb



On 2021-01-24 10:06 a.m., Peng Yu via Gdb wrote:
> Hi,
> 
> https://visualgdb.com/gdbreference/commands/set_disassembly-flavor
> 
> I am trying to follow the above example, but it does behave the same
> on Linux and Mac. Does anybody know how to make it work on Mac?
> Thanks.
> 
> On Linux:
> 
> $ uname Linux $ cat func.c int func(int a, int b) { return a + b; } $
> gcc -c func.c $ gdb -q func.o Reading symbols from func.o...  (No
> debugging symbols found in func.o) (gdb) show disassembly-flavor The
> disassembly flavor is "att".  (gdb) disassemble func Dump of assembler
> code for function func: 0x0000000000000000 <+0>:	push   %rbp
> 0x0000000000000001 <+1>:	mov    %rsp,%rbp 0x0000000000000004
> <+4>:	mov    %edi,-0x4(%rbp) 0x0000000000000007 <+7>:	mov
> %esi,-0x8(%rbp) 0x000000000000000a <+10>:	mov    -0x4(%rbp),%edx
> 0x000000000000000d <+13>:	mov    -0x8(%rbp),%eax
> 0x0000000000000010 <+16>:	add    %edx,%eax 0x0000000000000012
> <+18>:	pop    %rbp 0x0000000000000013 <+19>:	ret End of
> assembler dump.
> 
> On Mac:
> 
> $ uname Darwin $ cat func.c int func(int a, int b) { return a + b; } $
> gcc -c func.c $ gdb -q func.o Reading symbols from func.o...  (No
> debugging symbols found in func.o) (gdb) show disassembly-flavor The
> disassembly flavor is "att".  (gdb) disassemble func No symbol table
> is loaded.  Use the "file" command.
> 

It's probably not really the disassemble command that is different, it
looks like the Mac version did not read the minimal symbols properly.
You would have to debug GDB to understand why.  On Linux the minimal
symbols are read from the ELF executable, whereas on Mac it is from the
Mach-O executable.  Presumably, that happens in macho_symfile_read, in
machoread.c.  It looks like you can do "set debug mach-o 1" to enable
some debug prints about reading Mach-O executables, I don't know if that
will help or not.

You could also try building with debug symbols, but passing -g to the
compiled.

Simon

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

* Re: Why does `disassemble` behave differently on Linux and Mac?
  2021-01-24 15:06 Why does `disassemble` behave differently on Linux and Mac? Peng Yu
  2021-01-24 15:31 ` Simon Marchi
@ 2021-01-24 15:35 ` Eli Zaretskii
  2021-01-24 16:01   ` Peng Yu
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2021-01-24 15:35 UTC (permalink / raw)
  To: Peng Yu; +Cc: gdb

> Date: Sun, 24 Jan 2021 09:06:10 -0600
> From: Peng Yu via Gdb <gdb@sourceware.org>
> 
> $ gcc -c func.c
> $ gdb -q func.o
> Reading symbols from func.o...
> (No debugging symbols found in func.o)
> (gdb) show disassembly-flavor
> The disassembly flavor is "att".
> (gdb) disassemble func
> No symbol table is loaded.  Use the "file" command.

I think you need to compile with -g.

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

* Re: Why does `disassemble` behave differently on Linux and Mac?
  2021-01-24 15:35 ` Eli Zaretskii
@ 2021-01-24 16:01   ` Peng Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Peng Yu @ 2021-01-24 16:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb

Adding -g to gcc make `disassemble func` works. Why is it required on
Mac but not on Linux?

On 1/24/21, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Sun, 24 Jan 2021 09:06:10 -0600
>> From: Peng Yu via Gdb <gdb@sourceware.org>
>>
>> $ gcc -c func.c
>> $ gdb -q func.o
>> Reading symbols from func.o...
>> (No debugging symbols found in func.o)
>> (gdb) show disassembly-flavor
>> The disassembly flavor is "att".
>> (gdb) disassemble func
>> No symbol table is loaded.  Use the "file" command.
>
> I think you need to compile with -g.
>


-- 
Regards,
Peng

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

end of thread, other threads:[~2021-01-24 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24 15:06 Why does `disassemble` behave differently on Linux and Mac? Peng Yu
2021-01-24 15:31 ` Simon Marchi
2021-01-24 15:35 ` Eli Zaretskii
2021-01-24 16:01   ` Peng Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).