Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: Cannot access memory at address 0x0

  1. #1
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Cannot access memory at address 0x0

    Hi, it's me, again (sigh), I'm unsure whether I should post this on the KDevelop forum, the gdb one or qtcentre, so I'll start with the most specific one.
    I'm new to working with KDevelop. Yeah, I guess I should read some docs about it. (I normally work with MSVS)

    Here's the problem I'm having: I keep getting the following error when trying to debug: Cannot access memory at address 0x0. I've cut down my code and pinned down the problem to be at line 5, yet I'm still puzzled as of why it happens, I can't see what I'm doing wrong here. (naturally, it compiles just fine)

    Right, so here's the code.
    Qt Code:
    1. #include <QApplication>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Specs:
    Ubuntu 7.10
    KDevelop 3.5.0
    Last edited by defumar; 25th January 2008 at 15:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    Are you sure this is the code that causes trouble? It's perfectly valid. And accessing memory at address 0x0 means you are trying to dereference a null pointer.

  3. #3
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    I did a clean on the project dir, made the makefile etc again and left only the main.cpp in there and it still keeps giving me that error. I'll try starting a new project and copy pasting it in but this is really weird.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    Try compiling and running an empty file.

  5. #5
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    No error on compilation
    No error on debug for the following
    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. return 0;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Unless you meant compiling a truly empty file, 'cus that gave me: (.text+0x18): undefined reference to `main'
    which seems normal imo

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Cannot access memory at address 0x0

    What's the backtrace when "Cannot access memory at address 0x0" happens?
    J-P Nurmi

  7. #7
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    behold:
    (gdb) bt
    #0 main (argc=Cannot access memory at address 0x0
    ) at main.cpp:7
    ^done
    Last edited by defumar; 25th January 2008 at 16:02.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    How exactly did you compile the application? What happens if you change "*argv[]" to "**argv"? I know the former should work but it should all work and it doesn't so I'm curious to see the result.

  9. #9
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    Firstly I went into the src directory of my Simple Qt project and I ran qmake -project and qmake, then I opened up KDevelop again and had it Build Project using all the default settings for a qmake project. (g++)
    I tried changing it to ** but still got the same error.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    What is the contents of the .pro file?

  11. #11
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    Qt Code:
    1. SUBDIRS += src
    2. TEMPLATE = subdirs
    3. CONFIG += warn_on \
    4. qt \
    5. thread
    To copy to clipboard, switch view to plain text mode 

    I read that the -fstack-check option may cause an error like this. I have no idea of where to find it in my KDevelop though.
    The page I read this --> http://lists.trolltech.com/qt-intere.../msg00731.html
    Last edited by defumar; 26th January 2008 at 10:37.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    What's the contents of the .pro file inside the src subdirectory?

    Oh, and please rebuild your project without KDevelop. Open the console, cd into src, run qmake, make distclean, qmake, make.

  13. #13
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    oh right, here it is:
    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (2.01a) Fri Jan 25 13:56:09 2008
    3. ######################################################################
    4.  
    5. TEMPLATE = app
    6. TARGET =
    7. DEPENDPATH += .
    8. INCLUDEPATH += .
    9.  
    10. # Input
    11. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    Right I made it without KDevelop and this is what gdb gave me when stepping through code.
    Qt Code:
    1. ~/MToDo/src$ gdb src
    2. GNU gdb 6.6-debian
    3. Copyright (C) 2006 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i486-linux-gnu"...
    9. Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
    10. (gdb) break main
    11. Breakpoint 1 at 0x8048596: file main.cpp, line 5.
    12. (gdb) run
    13. Starting program: /home/defumar/MToDo/src/src
    14. [Thread debugging using libthread_db enabled]
    15. [New Thread -1224051008 (LWP 6910)]
    16. [Switching to Thread -1224051008 (LWP 6910)]
    17.  
    18. Breakpoint 1, main (argc=1, argv=0xbfb26af4) at main.cpp:5
    19. 5 QApplication app(argc, argv);
    20. (gdb) n
    21. Qt: gdb: -nograb added to command-line options.
    22. Use the -dograb option to enforce grabbing.
    23. 7 return 0;
    24. (gdb) n
    25. 8 }
    26. (gdb) n
    27. 0xb743b050 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
    28. (gdb) n
    29. Single stepping until exit from function __libc_start_main,
    30. which has no line number information.
    31.  
    32. Program exited normally.
    33. (gdb) q
    To copy to clipboard, switch view to plain text mode 

    backtrace after executing line 5 (evil line, ain't it) returns the same as before (argc=Cannot access mem at 0x0)
    Last edited by defumar; 26th January 2008 at 11:55.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    From the above output it seems the program executes correctly. Or am I wrong?

  15. #15
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    The above output shows that the program seems to execute correctly but in a different gdb session I backtraced a couple of times and noticed that after line 5 argc=Cannot access mem at 0x0
    Which doesn't seem correct to me though. argc should still be valid as it was at line 5. Instead it shows that apparantly it got corrupted :\ Correct me if I'm wrong.
    Last edited by defumar; 26th January 2008 at 14:13.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    Could you show us a print from a gdb session that segfaults the project? And are you sure this is not actually gdb that segfaults and not the project?

  17. #17
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    Qt Code:
    1. ~/MToDo/src$ gdb src
    2. GNU gdb 6.6-debian
    3. Copyright (C) 2006 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i486-linux-gnu"...
    9. Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
    10. (gdb) break main
    11. Breakpoint 1 at 0x8048596: file main.cpp, line 5.
    12. (gdb) run
    13. Starting program: /home/defumar/MToDo/src/src
    14. [Thread debugging using libthread_db enabled]
    15. [New Thread -1224476992 (LWP 6527)]
    16. [Switching to Thread -1224476992 (LWP 6527)]
    17.  
    18. Breakpoint 1, main (argc=1, argv=0xbf9218f4) at main.cpp:5
    19. 5 QApplication app(argc, argv);
    20. (gdb) bt
    21. #0 main (argc=1, argv=0xbf9218f4) at main.cpp:5
    22. (gdb) n
    23. Qt: gdb: -nograb added to command-line options.
    24. Use the -dograb option to enforce grabbing.
    25. 7 return 0;
    26. (gdb) bt
    27. #0 main (argc=Cannot access memory at address 0x0
    28. ) at main.cpp:7
    29. (gdb) p argc
    30. Cannot access memory at address 0x0
    31. (gdb) n
    32. 8 }
    33. (gdb) bt
    34. #0 main (argc=0, argv=0xa9) at main.cpp:8
    35. (gdb) n
    36. 0xb73d3050 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
    37. (gdb) n
    38. Single stepping until exit from function __libc_start_main,
    39. which has no line number information.
    40.  
    41. Program exited normally.
    To copy to clipboard, switch view to plain text mode 

    I am not sure whether the debugger messes up or the project itself, frankly I have no idea. Are there other debuggers I could try?

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    It's not the QApplication constructor that segfaults, look that something happens at line 7. argc changes from 1 to 0. Do examples bundles with Qt build and run correctly? Are you able to run any Qt4 based application?

  19. #19
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: Cannot access memory at address 0x0

    The examples run fine. Perhaps I should ignore the error? I tried debugging one of the examples which also gave me the "argc=Cannot access memory at address 0x0". I guess it's, uh... normal?

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot access memory at address 0x0

    Does it only happen when you debug? I think your gdb is invalid.

Similar Threads

  1. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  2. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  3. what is free store in C++ memory?
    By Masih in forum General Programming
    Replies: 6
    Last Post: 2nd July 2007, 22:25
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.