LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2010, 04:56 AM   #1
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Compiling source code for debugging (KDevelop/cmake)


Hi all,

I want to make a small improvement to the Krdc source code.
For that I want to debug the code.
However after building the binary file, gdb krdc,
setting a breakpoint and make the breakpoint being triggered... I step through the code and I want to use the print function to see the value of an integer.

I get the message:

<Value optimized out>

After a short search I noticed this is due to optimizations in the compilation code and the debugger not being able to read the value out.

I am using gentoo so I know about the -O option.
I created the project in KDevelop as a "Debug" project.

I changed some flags in the "Open Options", "Advanced settings" to use -O0.
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
...
Even then I still get the same issue.

DOes someone know what I should do? (I am not experienced with debugging and programming)
Thanks in advance!
 
Old 12-11-2010, 11:51 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
You may need to do a make clean after changing the flags to force the object files to be recompiled with the new optimization settings. You may need to recompile the libraries used by the program as well.
 
Old 12-11-2010, 05:59 PM   #3
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
Thanks for your answer.

I did make clean all. The libraries shouldn't be recompiled as the code I want to debug is not in any library.
I am still searching for a solution

EDIT:
I found out that the issue is actually due to cmake/default cxx flags.
Code:
#
/usr/bin/cmake -E cmake_echo_color --switch= --green "Building CXX object rdp/CMakeFiles/krdc_rdpplugin.dir/rdpview.o"
#
cd /home/xxx/kdenetwork-4.4.5/krdc/build/rdp && /usr/bin/c++   -DMAKE_KRDC_RDPPLUGIN_LIB -D_BSD_SOURCE -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -DQT_NO_STL -DQT_NO_CAST_TO_ASCII -D_REENTRANT -DKDE_DEPRECATED_WARNINGS -DKDE_DEFAULT_DEBUG_AREA=5012 -g3 -O0 -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline -fPIC -I/home/xxx/kdenetwork-4.4.5/krdc/build/rdp -I/home/xxx/kdenetwork-4.4.5/krdc/rdp -I/home/xxx/kdenetwork-4.4.5/krdc -I/home/xxx/kdenetwork-4.4.5/krdc/build -I/home/xxx/kdenetwork-4.4.5/krdc/core -I/home/xxx/kdenetwork-4.4.5/krdc/build/core -I/usr/include/KDE -I/usr/include/qt4/QtXmlPatterns -I/usr/include/qt4/QtXml -I/usr/include/qt4/QtWebKit -I/usr/include/qt4/QtUiTools -I/usr/include/qt4/QtTest -I/usr/include/qt4/QtSvg -I/usr/include/qt4/QtSql -I/usr/include/qt4/QtScriptTools -I/usr/include/qt4/QtScript -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtHelp -I/usr/include/qt4/QtDesigner -I/usr/include/qt4/QtDBus -I/usr/include/qt4/QtAssistant -I/usr/include/qt4/Qt3Support -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/usr/include/qt4/Qt -I/usr/share/qt4/mkspecs/default -I/usr/include/qt4   -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -o CMakeFiles/krdc_rdpplugin.dir/rdpview.o -c /home/xxx/kdenetwork-4.4.5/krdc/rdp/rdpview.cpp
There is both -g3 -O0 and -g -O2 after that. However I don't know how to fix this.

Last edited by deadeyes; 12-12-2010 at 11:51 AM.
 
Old 12-13-2010, 06:01 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by deadeyes View Post
There is both -g3 -O0 and -g -O2 after that. However I don't know how to fix this.
The last option is the one that takes effect, can you see how cmake is constructing that command line (post the cmakefile, maybe)?
 
Old 12-14-2010, 07:25 AM   #5
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Original Poster
Rep: Reputation: 79
Quote:
Originally Posted by ntubski View Post
The last option is the one that takes effect, can you see how cmake is constructing that command line (post the cmakefile, maybe)?
Someone pointed out that FindKDE4Internal.cmake is the actual cause.
I grepped for CMAKE_CXX_FLAGS_DEBUG and found that -g -O2 is configured there.

I changed it in that file. Of course it is more of a workaround than a fix so if you have any ideas on how to fix this I would be happy to hear it.

Is CMakeLists what you want?
Code:
project(krdc)

if(NOT INSIDE_KDENETWORK)
    message("Not building inside KDENetwork, loading KDE CMake Macros.")

    set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../cmake/modules ${CMAKE_MODULE_PATH})

    find_package(KDE4 REQUIRED)

    include(KDE4Defaults)
    include(MacroLibrary)

    include(CheckIncludeFile)
    include(CheckIncludeFiles)
    include(CheckSymbolExists)
    include(CheckFunctionExists)
    include(CheckLibraryExists)
    include(CheckPrototypeExists)
    include(CheckTypeSize)

    macro_optional_find_package(TelepathyQt4)
    macro_log_feature(TELEPATHY_QT4_FOUND "telepathy-qt4" "Telepathy Qt Bindings" "https://telepathy.freedesktop.org" FALSE "0.18" "Needed to build Telepathy Tubes support.")

    set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS})
    if(WIN32)
       set(CMAKE_REQUIRED_LIBRARIES ${KDEWIN32_LIBRARIES})
       set(CMAKE_REQUIRED_INCLUDES  ${KDEWIN32_INCLUDES})
    endif(WIN32)
    add_definitions(${QT_DEFINITIONS} ${QT_QTDBUS_DEFINITIONS} ${KDE4_DEFINITIONS})
    include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})

    macro_optional_find_package(LibVNCServer)
    macro_log_feature(LIBVNCSERVER_FOUND "libvncserver" "VNC Server library" "http://libvncserver.sourceforge.net/" FALSE "0.9" "Needed to build Krfb and VNC support in Krdc")

    # NX support is not ready for KDE 4.2; disabled (uwolfer)
    # macro_optional_find_package(LibNXCL)
    # macro_log_feature(LIBNXCL_FOUND "libnxcl" "NX X compression client library" "http://svn.berlios.de/svnroot/repos/freenx/trunk/freenx-client/nxcl/" FALSE "1.0" "Needed to build Krdc with NX support")

	if(TELEPATHY_QT4_FOUND)
    	add_definitions(-DTELEPATHY_SUPPORT)
    	include_directories(${TELEPATHY_QT4_INCLUDE_DIR})
	endif(TELEPATHY_QT4_FOUND)

endif(NOT INSIDE_KDENETWORK)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/core/
    ${CMAKE_CURRENT_BINARY_DIR}/core/
    ${CMAKE_CURRENT_BINARY_DIR}
)

add_subdirectory(core)
add_subdirectory(vnc)
add_subdirectory(nx)
add_subdirectory(rdp)
add_subdirectory(test)

if(TELEPATHY_QT4_FOUND)
    add_subdirectory(krdc_approver)
endif(TELEPATHY_QT4_FOUND)

add_definitions(-DKDE_DEFAULT_DEBUG_AREA=5010)
add_definitions(-DBUILD_ZEROCONF)

set(krdc_SRCS
    config/hostpreferenceslist.cpp
    config/preferencesdialog.cpp
    floatingtoolbar.cpp
    bookmarkmanager.cpp
    remotedesktopsitem.cpp
    remotedesktopsmodel.cpp
    systemtrayicon.cpp
    tabbedviewwidget.cpp
    mainwindow.cpp
    main.cpp
)

if(TELEPATHY_QT4_FOUND)
    set(krdc_SRCS ${krdc_SRCS}
        tubesmanager.cpp
        tube.cpp
    )
endif(TELEPATHY_QT4_FOUND)

kde4_add_ui_files(krdc_SRCS
    config/general.ui
)

kde4_add_executable(krdc ${krdc_SRCS})

target_link_libraries(krdc
    ${KDE4_KFILE_LIBS}
    ${KDE4_KIO_LIBS}
    ${KDE4_KNOTIFYCONFIG_LIBS}
    ${KDE4_KUTILS_LIBS}
    krdccore
)

if(TELEPATHY_QT4_FOUND)
    target_link_libraries(krdc
        ${TELEPATHY_QT4_LIBRARIES}
    )
endif(TELEPATHY_QT4_FOUND)

target_link_libraries(krdc ${KDE4_KDNSSD_LIBS})

install(TARGETS krdc ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES krdcui.rc DESTINATION ${DATA_INSTALL_DIR}/krdc)
install(FILES krdc.desktop DESTINATION ${XDG_APPS_INSTALL_DIR})
install(FILES pointcursor.png pointcursormask.png DESTINATION ${DATA_INSTALL_DIR}/krdc/pics)

if(TELEPATHY_QT4_FOUND)
    configure_file(org.freedesktop.Telepathy.Client.krdc_rfb_handler.service.in
                    ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.krdc_rfb_handler.service)
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Telepathy.Client.krdc_rfb_handler.service
            DESTINATION ${DBUS_SERVICES_INSTALL_DIR})

    install(FILES krdc_rfb_handler.client DESTINATION ${SHARE_INSTALL_PREFIX}/telepathy/clients/)
endif(TELEPATHY_QT4_FOUND)

if(NOT INSIDE_KDENETWORK)
    macro_display_feature_log()
endif(NOT INSIDE_KDENETWORK)
Thanks in advance!
 
Old 12-14-2010, 02:49 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by deadeyes View Post
Someone pointed out that FindKDE4Internal.cmake is the actual cause.
I grepped for CMAKE_CXX_FLAGS_DEBUG and found that -g -O2 is configured there.

I changed it in that file. Of course it is more of a workaround than a fix so if you have any ideas on how to fix this I would be happy to hear it.
Given that
a workaround is required, but it may be cleaner to set CMAKE_CXX_FLAGS_DEBUG in your own cmake file rather than in the KDE internals.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
debugging nasm source code rblampain Programming 2 12-05-2010 08:17 AM
LXer: Open Source rocks, learning from code by debugging LXer Syndicated Linux News 0 05-13-2009 01:40 PM
facing problem in kernel debugging(not able to find source code) through lauterbach vrsonu Linux - Mobile 0 04-14-2009 05:34 AM
linux debugging without source code Newbie123 Programming 2 03-10-2002 01:12 PM
debugging without source code Newbie123 Linux - Newbie 3 03-10-2002 12:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration