Home > front end >  Makefile not generating debugging information with -g flag
Makefile not generating debugging information with -g flag

Time:01-27

I recently moved from working in the terminal to VScode and am needing to generate debugging information to use with the debugger in vscode.

My makefile is:

SRCS =  src/ft_argcheck.c       \
        src/ft_operations.c     \
        src/ft_stcutils.c       \
        src/push_swap.c

NAME    = push_swap
INCS    = inc/push_swap.h
OBJS    = $(SRCS:c=o)
CC      = gcc
CFLAGS  = -g -Wall -Wextra -Werror
RM      = rm -f
LIBFT = libft/libft.a
LIBFT_DIR = libft

.PHONY: all bonus clean fclean re

all: $(NAME)

$(NAME): $(OBJS)
    @make -C $(LIBFT_DIR) --silent
    @$(CC) $(CFLAGS) -I$(INCS) -o $(NAME) $(OBJS) -L $(LIBFT_DIR) -lft

clean:
    @$(RM) $(OBJS)
    @make -s clean -C $(LIBFT_DIR)

fclean: clean
    @$(RM) $(NAME)
    @make -s fclean -C $(LIBFT_DIR)

re: fclean all

But despite adding the -g flag, no debugging information is generated. on which I can run lldb.

CodePudding user response:

A good proposal is to remove the @s in front of the command names to see what commands make is executing.... To make a program debuggable, you need to check that all the compilation steps are done using the -g flag and that the linking step has also included the -g flag. Also a good option is to specify no optimization so you will not get to problems with breakpoints you cannot fix because the compiler has eliminated or changed the final code, and has broken the correspondence between source lines and points in the code.

If you take off all the @s there, you will see the commands as make is executing them, think you don't see now. I think there's a command (berkeley make has it) to make make to print the commands even though the @s remain in place.

By the way, as you are telling you are using vscode it should be fine if you execute make on the command line alone, to see the output of the commands, and try to see if it is some problem with make or with vscode itself.

As you have not provided your complete project, I'm sorry to say that I can only test it with dumb/fake files and no program can be made to test it with gdb.

I guess that the problem is that you have put your project sources in a different directory than where the program is built, and the sources cannot be found by gdb and so, no source debugging can be done because gdb cannot find the source files. Gdb has some way to specify the path to the source files... You should look at gdb documentation.

CodePudding user response:

Thanks for all your answers (Removing @ didn't really give me much more information, as it did show the -g flag and I already tried remaking everything with fclean). I seem to have figured out an easy fix with the help of a friend:

add a rule "debug"

debug: 
    $(CC) -g $(CFLAGS) -I$(INCS) $(LIBFT) $(SRCS) -o $(NAME)

which we can run just when we want to generate the debugging information and run this directly with $(SRCS) instead of running it on the $(OBJS) as in the normal command.

  •  Tags:  
  • Related