2

In a book I read, the author's CPU was 32-bit. Mine is 64-bit. I run the NASM assembler in the terminal with:

nasm -f elf -g -F stabs asmwork/eatsyscall.asm

Then I run the linker:

ld -o eatsyscall eatsyscall.o

This returned:

ld: i386 architecture of input file eatsyscall.o is incompatible with i386:x86-64 output

I read some answers and it said I needed to use elf64 (not as the book said). I run the assembler and it solved this message.

Now I run in the terminal kdbg eatsyscall.o. It opens the KDbg software and KDbg: Program output.

I select a breakpoint in a line and as usual a red circle appears. I click run and the red circle is not changed for an arrow. Instead in the KDbg: Program output it outputs this message (I'm not showing where the .o file is as in the output it is written):

warning: GDB: Failed to set controlling terminal: Operation not permitted 
/bin/bash: Permission denied 
/bin/bash: line 0: exec: cannot execute: Permission denied.

Or on one occasion, just this message:

warning: GDB: Failed to set controlling terminal: Operation not permitted

In Settings > Global Options I have the following.

  • How to invoke GDB: gdb --fullname --nx
  • Terminal for program output: xterm -name kdbgio -title %T -e sh -c %C

What can I do? Why do I get a permission error? Is it something related to the command sudo?


UPDATE

For running the debugger I have used kdbg program and kdbg ./program. The executable file I want to debug is called program and it is located in the folder asmwork. When my working directory is with that folder, I write ls -l and I get the following about the file:

-rwxrwxr-x 1 user user 1304 יול 24 17:56 program

this

this

1 Answers1

1

I see that this is old. However, it is unanswered and it is receiving significant views, hence…..

I read some answers and it said I needed to use `elf64` (not as the book said).

The book in question is really about programming in assembly language for Intel’s 32-bit x86 CPU’s, this is explicitly stated throughout, and in any of the marketing literature that I have seen. You’ll need to be mindful of subtle differences between the IA-32 and x86-64 architectures. If you are using a x86-64 PC, it stands to reason that some of the examples given in the text may need tweaking slightly.

In addition to changing elf to elf64, it would be wise to replace stabs with dwarf, as in my experience, assembling your program with stabs in x86-64 is not entirely compatible; stabs would be a more appropriate format for working with IA-32 Linux.

Again, it is up to you to decipher where the examples given in the text need adjusting for the change in technology.

nasm -f elf -g -F stabs eatsyscall.asm

becomes...............

nasm -f elf64 -g -F dwarf eatsyscall.asm

This should successfully compile your source code into a x86-64 compatible object code file. ...................................................................................................................................................................

Using elf format as opposed to elf64, will assembly a x86 object code file. You can then create a 32-bit executable using the following:

ld -m elf_i386 -o executablename objectfilename.o

Option -m is for Emulation (please see ld man pages). Here you can select your desired architecture, from those available. Using -m elf_i386 enables us to create a i386 executable on our x86-64 machine.

You can use option -V to get a list of available architectures; please see man pages for full details.

..............................................................................

I run in the terminal `kdbg eatsyscall.o`. It opens the Kdbg software and Kdbg: Program output

You will need to load an executable file into the debugger, not an object code file as above. You have already created this executable, assuming it was successful, when you ran the object module through the linker; as stated in your question.

Your main concern appears to be with the warning in the output terminal window.

The solution can be sought in the manual. I’ll reproduce the solution here, in case the URL fails in future.

When a program is debugged with KDbg for the first time, the program
output window is not used. The reason for this is that KDbg cannot know whether the program requires sophisticated terminal emulation or if it expects input through a terminal. So, a terminal emulator program is used by default. In order to redirect the output to the output window, you must do the following:

  1. Open the Settings dialog by selecting Settings|This Program.
  2. Switch to the Output tab.
  3. Choose Only output, simple terminal emulation and click OK.
  4. Reload the program by selecting it from the list in File|Recent > Executables.