当前位置: 技术问答>linux和unix
30分求如何用gdb调试c语言和汇编混合编写的程序
来源: 互联网 发布时间:2016-10-11
本文导语: 现有如下三个文件: 1. nasm汇编文件,文件名称为foo.asm内容为: extern choose [section .data] num1st dd 3 num2nd dd 4 [section .text] global _start global myprint _start: push dword [num2nd] push dword [num1st] call choose add esp, 8 mov ebx, ...
现有如下三个文件:
1. nasm汇编文件,文件名称为foo.asm内容为:
extern choose
[section .data]
num1st dd 3
num2nd dd 4
[section .text]
global _start
global myprint
_start:
push dword [num2nd]
push dword [num1st]
call choose
add esp, 8
mov ebx, 0
mov eax, 1
int 0x80
myprint:
mov edx, [esp + 8] ; len
mov ecx, [esp + 4] ; msg
mov ebx, 1
mov eax, 4
int 0x80
ret
2. c语言文件,文件名称为bar.c内容为:
void myprint(char* msg, int len);
int choose(int a, int b) {
if(a >= b){
myprint("the 1st onen", 13);
}
else{
myprint("the 2nd onen", 13);
}
return 0;
}
3. make文件,文件名称为Makefile内容为:
ASM = nasm
CC = gcc
LD = ld
ASMFLAGS = -f elf
CFLAGS = -c
LDFLAGS = -s
BIN = foobar
OBJS = foo.o bar.o
everything : $(BIN)
all : everything
$(BIN) : $(OBJS)
$(LD) $(LDFLAGS) -o $(BIN) $(OBJS)
foo.o : foo.asm
$(ASM) $(ASMFLAGS) -o $@ $
1. nasm汇编文件,文件名称为foo.asm内容为:
extern choose
[section .data]
num1st dd 3
num2nd dd 4
[section .text]
global _start
global myprint
_start:
push dword [num2nd]
push dword [num1st]
call choose
add esp, 8
mov ebx, 0
mov eax, 1
int 0x80
myprint:
mov edx, [esp + 8] ; len
mov ecx, [esp + 4] ; msg
mov ebx, 1
mov eax, 4
int 0x80
ret
2. c语言文件,文件名称为bar.c内容为:
void myprint(char* msg, int len);
int choose(int a, int b) {
if(a >= b){
myprint("the 1st onen", 13);
}
else{
myprint("the 2nd onen", 13);
}
return 0;
}
3. make文件,文件名称为Makefile内容为:
ASM = nasm
CC = gcc
LD = ld
ASMFLAGS = -f elf
CFLAGS = -c
LDFLAGS = -s
BIN = foobar
OBJS = foo.o bar.o
everything : $(BIN)
all : everything
$(BIN) : $(OBJS)
$(LD) $(LDFLAGS) -o $(BIN) $(OBJS)
foo.o : foo.asm
$(ASM) $(ASMFLAGS) -o $@ $