RKum
RKum

Reputation: 831

GDB not displaying code statments

I have bunch of source code which I compiled using -ggdb3 flag. I have copied the source code and executable to an another machine. When I run the exe in gdb it does not show the statements at the line numbers when it breaks.

This is what I see

Breakpoint 1, TestCode (handler=0x806e110, args=0xffffd2b0)
    at ../myfile.c:1080
1080    ../myfile.c: No such file or directory.
(gdb) n
1083    in ../myfile.c
(gdb) 
1084    in ../myfile.c
(gdb) 
1085    in ../myfile.c

I even tried setting the dir path using gdb dir command by giving the name of the topmost directory of the source code but no help. Example my source code directory structure is like

            C
            |
         --------------
        |              |
        D              E
        |
        F
        |
   -----------
  |           |
  S           T

The file I am debugging may be in some inner folder say F. While I gave the path of folder C in gdb dir

dir /home/C

Any way to resolve this issue?

More details are:

> OS SUSE Linux Enterprise Server 11 (x86_64)
> gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) 
> GNU gdb (GDB) SUSE (7.5.1-0.7.29)

Here are the Makefile details

#
# Makefile for building demo code on SUSE Linux

all : SLIBINSTALLDIR = $(SDESTDIR)$(SLIBDIR)

###########################################
#               Defines                   #
###########################################

CC = --mode=compile gcc
LINK =$(DESTDIR)libtool --mode=link gcc
INDEPSDIR = ../../../../../dependencies/internal
MODULE = TestCode

INCLUDE = -I../ -I$(INDEPSDIR)/include
CFLAGS := $(CFLAGS) $(INCLUDE)  -DN_PLAT_UNIX -DN_PLAT_GNU -DVERSION=0x00010002 -D_GNU_SOURCE -g -ggdb3


CSRC  = ../myfile.c ../decode.c  ../encode.c
COBJ = $(CSRC:.c=.o)
COBJ1 = $(CSRC:.c=.lo)

TestCode:$(COBJ)
         $(LINK) $(CFLAGS)  -o TestCode $(COBJ1) -all-static 

DESRC  = ../main.c
DEOBJ = $(DESRC:.c=.o)

Upvotes: 2

Views: 1841

Answers (1)

ks1322
ks1322

Reputation: 35785

You should define a source path substitution rule using command:

set substitute-path from to

It will substitute from part into to allowing to find sources in new location. See https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html.

Also info sources command will be useful to remember from part in the command above in case you forgot where your sources were located before copying.

Upvotes: 3

Related Questions