FedoraForum.org - Fedora Support Forums and Community
Page 2 of 2 FirstFirst 1 2
Results 16 to 23 of 23
  1. #16
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    596

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    Quote Originally Posted by ocratato
    I left the second link off my list as it failed to mention the back trace command, which is the one I use about 99% of the time.
    I use "break if var!=val" or similar quite a lot. You know those annoying situations where your program will run green for a while and then randomly go red for no apparent reason, being able to pause the program at the moment it flicks to red ready for investigation is really useful.

  2. #17
    Join Date
    Jun 2005
    Location
    Montreal, Que, Canada
    Posts
    4,708

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    I always use the following two macros as the entry into my source or header file
    #ifndef debug
    #define debug(M, ...)
    #endif
    #ifndef debug1
    #define debug1(M, ...) fprintf(stderr, "DEBUG %s %s %d: " M "\n",__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__ );
    #endif


    In the code, I when I want to see the debug contents, I just replace debug(...) by debug1(...)
    sample below

    Code:
    char *get_labelVal(dictionary *ini, const char *inkey)
    {
         char label[64];
         *label=LABELSTMT;       
         debug("inkey=%s",inkey);                  //set debug to debug1. to display the line of text 
         strncpy(label+1,inkey,sizeof(label)-1);
         return (char *)dictionary_get(ini,label,twelvestars);
    }
    If you use debug(...); nothing gets compiled. If you change debug to debug1, the contents of debug1( ) get compiled.
    During development, I lace the code at critical points (not inside loops), with debug( .... )
    Turning on debug1() at critical points is better than using a global debug macro for the entire source.
    I used to have multiple macros, but found I didn't need them if I just used the above two.
    Leslie in Montreal

    Interesting web sites list
    http://forums.fedoraforum.org/showth...40#post1697840

  3. #18
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    2,732

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    I think we are drifting a bit too far off the topic of tutorials for gcc and gdb.

    Perhaps a new thread on debugging techniques might be useful.

  4. #19
    Join Date
    Jun 2005
    Location
    Montreal, Que, Canada
    Posts
    4,708

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    Hi Tangent144.

    gdb is a great tool, and you have the tutorial references given that are great.

    But sometimes, you want to examine a program that was compiled using maximum optimization. An optimesing compiler may not work well with gdb. gdb is going to help tell you where your program failed, but what if the problem failure occurs some minutes after handling lots of data, such as after processing a thousand or more transactions/records.

    Its good to have an accompaniment to gdb, From my "developer's toolbox" I presented (response #17) the two macros that I use as a gdb alternative or gdb accompaniment. I would also add to your collection, the libc.pdf available from gnu.org
    Leslie in Montreal

    Interesting web sites list
    http://forums.fedoraforum.org/showth...40#post1697840

  5. #20
    Join Date
    Jun 2017
    Location
    Brazil
    Posts
    22

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    I am an absolute beginner and I am reading Stephen Prata's "C Primer Plus" (6th edition) to get a basic comprehension of C. However, the book has a program doesn't compile and I would like to debug it; but I don't understand gdb and the tutorials. But I found a book about gdb in Amazon. It's a two volume set, and it's compatible with gdb 7.x. So, I think to buy it anyway.

  6. #21
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    596

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    Quote Originally Posted by tangent144
    However, the book has a program doesn't compile and I would like to debug it; but I don't understand gdb and the tutorials.
    If the program won't compile the compiler (gcc) should tell you why, for example "this function expects an integer but you've passed a string to it". GDB is used for the next step of debugging, i.e: "the program compiles & it runs, but it's giving me some weird results, lets dig in to it and see what's going on". I usually use Valgrind as a next/other step for issues like "it compiles, it runs and it's consistently giving me the expected results... but it's memory use is growing over time. Let's see where".

    What error is gcc giving you?

  7. #22
    Join Date
    Jun 2017
    Location
    Brazil
    Posts
    22

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    menuette.c: In function 'main':
    menuette.c:29:8: error: static declaration of 'count' follows non-static declaration
    void count(void)
    menuette.c:10:8: note: previous declaration of 'count' was here
    void count(void);
    menuette.c:79:1: error: expected delcaration or statement at end of input
    }
    At top level:
    menuette.c:65:6: error: 'get_int' defined but not used [-Werror=unused-function]
    int get_int(void)
    menuette.c:55:7: error: 'get_first' defined but not used [-Werror=unused-function]
    char get_first(void)
    menuette.c:40:7: error "get_choice' defined but not used [-Werror=unused-function]
    char get_choice(void)
    menuette.c:29:8: error: 'count' defined but not used [-Werror=unused-function]
    void count(void)
    cc1: all warningd being treated as errors

  8. #23
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    596

    Re: Does somebody know where can I find gcc and gdb tutorials for beginners

    Quote Originally Posted by tangent144
    menuette.c: In function 'main':
    menuette.c:29:8: error: static declaration of 'count' follows non-static declaration
    void count(void)
    menuette.c:10:8: note: previous declaration of 'count' was here
    void count(void);
    menuette.c:79:1: error: expected delcaration or statement at end of input
    }
    I think you might have copied the code from the book wrong, those blue lines look fine apart from the fact they're "IN FUNCTION MAIN" see red line, i.e: you're creating a function within the main function. They should be on their own, compare this code which compiles fine:

    Code:
    haydn@darkstar tmp]$ cat test.c 
    #include <stdio.h>
    
    void count(void);
    
    void count(void) {
      fprintf(stderr, "Count\n");
    }
    
    void main() {
      count();
      fprintf(stderr, "Done\n");
    }
    [haydn@darkstar tmp]$ gcc -o foo test.c 
    [haydn@darkstar tmp]$

    With this code which doesn't compile with the same error you've given and the in function main line. The only difference is I've moved the "void main() {" line up to above the other function definitions:

    Code:
    [haydn@darkstar tmp]$ cat testB.c 
    #include <stdio.h>
    
    void main() {
      void count(void);
    
      void count(void) {
        fprintf(stderr, "Count\n");
      }
    
      count();
      fprintf(stderr, "Done\n");
    }
    [haydn@darkstar tmp]$ gcc -o foo testB.c 
    testB.c: In function ‘main’:
    testB.c:6:8: error: static declaration of ‘count’ follows non-static declaration
       void count(void) {
            ^~~~~
    testB.c:4:8: note: previous declaration of ‘count’ was here
       void count(void);
            ^~~~~
    [haydn@darkstar tmp]$

Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Best books for beginners
    By EuGenie in forum Using Fedora
    Replies: 7
    Last Post: 8th July 2013, 12:49 PM
  2. Replies: 1
    Last Post: 28th March 2009, 02:59 AM
  3. Replies: 0
    Last Post: 28th March 2009, 02:37 AM
  4. beginners C++ compiler
    By fengshaun in forum Programming & Packaging
    Replies: 16
    Last Post: 29th December 2007, 07:31 PM
  5. Beginners help
    By 357mag in forum Using Fedora
    Replies: 3
    Last Post: 9th February 2005, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •