Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't debug inside library project #197

Closed
graph opened this issue Sep 12, 2016 · 10 comments
Closed

Can't debug inside library project #197

graph opened this issue Sep 12, 2016 · 10 comments
Labels

Comments

@graph
Copy link

graph commented Sep 12, 2016

Setup. 2 projects app project and libModule. This bug has 2 parts which I think are related so I'm putting both parts here.

Part 1: Can't debug library project, setting breakpoints do not work. And when a segfault happens ndk breaks in "unknown function` and nothing useful can be done.

A workaround solution is in the main project do this:

        // default config
        externalNativeBuild {
            cmake {
                abiFilters'armeabi-v7a'
                arguments "-DANDROID_PLATFORM=android-${platformVersion}",
                        '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_shared'
            }
        }
    // in android {}
    externalNativeBuild {
        cmake {
            path "../libModule/src/main/cpp/CMakeLists.txt"
        }
    }

and I can debug just fine. So far it's fine. This has the disadvantage of compiling everything twice.

part 2: Library project always compiles in the release folder .externalNativeBuild regardless what has been specified. Interesting though if I do "Build->build APK" in android studio RC2 it builds the debug build.

Some discussion here

Some version specifiers

Android Studio 2.2 RC 2
Build #AI-145.3253452, built on September 7, 2016
JRE: 1.8.0_76-release-b03 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

classpath 'com.android.tools.build:gradle:2.2.0-rc2'

compileSdkVersion 24
buildToolsVersion "24.0.2"

            cmake {
                abiFilters'armeabi-v7a'
                arguments "-DANDROID_PLATFORM=android-19",
                        '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_shared'
            }
@DanAlbert
Copy link
Member

I assume you're debugging with LLDB (via Android Studio) and not GDB (via ndk-gdb), right?

@graph
Copy link
Author

graph commented Sep 12, 2016

Yes via Android Studio. I'm pressing the Debug App button with everything at defaults in android studio RC2. Everything is at defaults:

Target channels: lldb process:gdb-remote packets
Debug Type: Hybrid

Is there instructions for how to use ndk-gdb with new cmake system? I haven't looked into ndk-gdb at all.

@DanAlbert
Copy link
Member

I think ndk-gdb is only set up to work with ndk-build projects, but @jmgao can correct me if I'm wrong.

For the Studio and LLDB issues, none of those components are actually in the NDK. Could you file a bug against Android Studio so they can take a look at it? http://tools.android.com/filing-bugs

@graph
Copy link
Author

graph commented Sep 12, 2016

Ok filed under Android Studio.

@mondaugen
Copy link

I know this is closed but I found this when having the same problem. I found a solution that worked for me:
If your external library is built with debugging symbols, you might have to do
add-dsym /path/to/shared/library
in the LLDB console to get the debugging info. You can set a breakpoint at some main point that you know is getting called, then use breakpoint command add to run commands loading the missing debugger symbols.

@knumat
Copy link

knumat commented Mar 3, 2019

I spent a few hours trying to make the debugger actually stop on a breakpoint in some native C++ code that was built into a library. Eventually I got it working by doing the following (under Android Studio 3.3.1). Hopefully this helps someone else!

  • Select Run -> Edit Configurations
  • On the left side, select Android App -> app
  • On the right side, select the Debugger tab
  • Under the Symbol Directories sub-tab, press the + button
  • Browse to the following path:
    libModule/build/intermediates/cmake/debug/obj
  • In the Build Variants window, select the "debug" configuration for the app

@Amoystyle
Copy link

Amoystyle commented Aug 15, 2019

if you use "set(CMAKE_C_FLAGS/CMAKE_CXX_FLAGS "")" in CMakeLists.txt, it will overwrite the compiler default mode, causing debug symbols to be lost.

TODO:
set(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} ”}
set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} ”)

@JessHolle
Copy link

I spent a few hours trying to make the debugger actually stop on a breakpoint in some native C++ code that was built into a library. Eventually I got it working by doing the following (under Android Studio 3.3.1). Hopefully this helps someone else!

  • Select Run -> Edit Configurations
  • On the left side, select Android App -> app
  • On the right side, select the Debugger tab
  • Under the Symbol Directories sub-tab, press the + button
  • Browse to the following path:
    libModule/build/intermediates/cmake/debug/obj
  • In the Build Variants window, select the "debug" configuration for the app

Yes, this did help me. And I see the issue here was closed and one opened in Android Studio -- as I was about to gripe that this should be automatic in Android Studio.

@alexsorokoletov
Copy link

Thank you, this is the only thing that helped 🥳
Could not debug C++/native android code, tried everything from SO and other sources I could find and this is the only thing that made the change. I am using Android Studio 4 (4.1) and MacOS
#197 (comment)

@JessHolle
Copy link

@alexsorokoletov I should note that I no longer have to do this in Android Studio 4.1.x with the Android Gradle Plugin 4.1.x -- thankfully.

@android android locked as resolved and limited conversation to collaborators Aug 11, 2022
@android android deleted a comment from maddam124 Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants
@DanAlbert @graph @alexsorokoletov @mondaugen @Amoystyle @JessHolle @knumat and others