Topics

debug makefile based c-helloworld application


Christian Schmidt
 

I try to debug a simple helloworld program but i can't see the source code. My approach:


hello.c

```

#include<stdio.h>

int main() {
  printf("Hello World\n");
  return 0;
}

```

hellome.bb

```

#
# This file was derived from the 'Hello World!' example recipe in the
# Yocto Project Development Manual.
#
SUMMARY = "Simple helloworld application"
LICENSE = "CLOSED"


SRC_URI = "file://hello.c"

S = "${WORKDIR}"

TARGET_CC_ARCH += "${LDFLAGS}"

do_compile() {
  ${CC} hello.c -o -g -O0 hello
}

do_install() {
  install -d ${D}${bindir}
  install -m 0755 hello ${D}${bindir}
}

```

Makefile

```
SOURCES=hello.c
OBJECTS=$(SOURCES:.c=.o)
EXEC=hello

#EXTRACFLAGS=-ansi

all: $(SOURCES) $(EXEC)

$(EXEC): $(OBJECTS)
    $(CC) $(CFLAGS) $(EXTRACFLAGS) $(OBJECTS) -o $@

%.o : %c
    $(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<

install:
    install $(EXEC) $(DESTDIR)/usr/bin

clean:
    rm -rf *.o $(EXEC)
```


local.conf

```

....

IMAGE_INSTALL_append = " hellome hellome-dbg hellome-dev"

EXTRA_IMAGE_FEATURES += "\
      dbg-pkgs \
      tools-debug \
      debug-tweaks \
      dev-pkgs"


# Specifies to build packages with debugging information
DEBUG_BUILD = "1"

# Do not remove debug symbols
INHIBIT_PACKAGE_STRIP = "1"

```


on the target:

```

root@qemuarm:~# hello
Hello World

root@qemuarm:~# gdb /usr/bin/hello

Reading symbols from /usr/bin/hello...
(gdb) b main
Breakpoint 1 at 0x518
(gdb) r
Starting program: /usr/bin/hello

Breakpoint 1, 0x00400518 in main ()
(gdb) list
1       longjmp.c: No such file or directory.
(gdb) list 1
file: "../setjmp/longjmp.c", line number: 1, symbol: "???"
1       ../setjmp/longjmp.c: No such file or directory.
file: "longjmp.c", line number: 1, symbol: "???"
1       longjmp.c: No such file or directory.
```