Debugging on Xcode for macOS

793 views
Skip to first unread message

Stefano Bider

unread,
Apr 8, 2020, 12:31:06 PM4/8/20
to discuss-webrtc
Hey everyone, I am developing a macOS app that needs to link against libwebrtc.a, but I am having troubles debugging through the code. 
If I set breakpoints in any of the WebRTC source files, all I see in Xcode is assembly code - which is not the case for any of my own files.

My Xcode project (PROJ) has two targets: one main ObjC app (APP) and one static C++ library (LIB). APP links against LIB, and LIB links against libwebrtc.a (that's how I need it to be).
The project products.xcodeproj generated by GN is included as a subproject of PROJ, which should allow debugging of the webrtc source.
LIB has all the proper header search paths set and the webrtc headers are properly found (note that the webrtc checkout is at ../../webrtc/src/ relative to PROJ)
I can navigate through the code while not running, jump to definitions and all.
The code compiles and runs and at the moment it does nothing more that calling CreatePeerConnectionFactory().
So if I set breakpoints in my code everything works as expected, but as soon as I step into a webrtc function (e.g. CreatePeerConnectionFactory()) I see only assembly code.
Another thing that does not work properly is code completion when it comes to including the webrtc headers. As an example, #include "api/create_peerconnection_factory.h" is properly resolved, but when writing "api/c.. ", xcode does not suggest anything. This, to me, is yet another a symptom that something is wrong.

I am developing on macOS 10.15.3 Catalina using Xcode 11.4.
I cloned the repository a couple of days ago following the instructions found at https://webrtc.github.io/webrtc-org/native-code/ios/ .
The gn command I used was:
gn gen out/macos/Debug --args='is_debug=true symbol_level=2'--ide=xcode

but I also tried omitting symbol_level altogether.

Does anyone have the same issue?
Thanks

Stef

Kiran Thind

unread,
Apr 9, 2020, 8:12:10 AM4/9/20
to discuss...@googlegroups.com
For C++ development on Mac check out CLion or even VS Code. The args I’m currently using to build against m83 (release) are:

use_rtti=true
is_debug=false
libcxx_abi_unstable=false


On Apr 8, 2020, at 9:31 AM, Stefano Bider <stefan...@gmail.com> wrote:


--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/129a439a-7af8-4cf7-b851-c16143f4912f%40googlegroups.com.

Stefano Bider

unread,
Apr 9, 2020, 8:29:46 AM4/9/20
to discuss-webrtc
Thanks for the answer, but my workflow involves xcode and, given that only that IDE is "supported" by webrtc, I see no reason to switch to either another (paid) IDE or simple code editor!
To unsubscribe from this group and stop receiving emails from it, send an email to discuss...@googlegroups.com.

Alexandre GOUAILLARD

unread,
Apr 9, 2020, 8:31:38 PM4/9/20
to discuss...@googlegroups.com
have you using a debug build?  (is_debug=true)

are you setting the symbols setting to the right value ?
=> check the doc this way: gn args out/mybuild --list=symbol_level


symbol_level

    Current value (from the default) = -1

      From //build/config/compiler/compiler.gni:39


    How many symbols to include in the build. This affects the performance of

    the build since the symbols are large and dealing with them is slow.

      2 means regular build with symbols.

      1 means minimal symbols, usually enough for backtraces only. Symbols with

    internal linkage (static functions or those in anonymous namespaces) may not

    appear when using this level.

      0 means no symbols.

      -1 means auto-set according to debug/release and platform.


To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/181a9980-7e3d-4f05-9b6d-95a21f0ad175%40googlegroups.com.


--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
President - CoSMo Software Consulting, Singapore
------------------------------------------------------------------------------------

Stefano Bider

unread,
Apr 10, 2020, 3:29:15 AM4/10/20
to discuss...@googlegroups.com
Yes to both questions: is debug and symbol_level=2

You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/discuss-webrtc/mlFuogg3IyU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/CAHgZEq6Wg4pia6gdJE%2B%3DC24%3D5n_Y4C8Hhuf_Xw2nx781okD2sQ%40mail.gmail.com.
--
--
Stefano Bider
phone : +43 660 64 111 07

Roman Gaiu

unread,
Apr 14, 2020, 4:37:46 AM4/14/20
to discuss-webrtc
Sometimes Xcode can't find source file because symbols have relative paths.
You can check how your paths to source look like with:
(lldb) image lookup -vn <webrtc symbols>
And if you see relative path for CompileUnit you can remap it:
(lldb) settings set target.source-map . <absolute path>

Stefano Bider

unread,
Apr 14, 2020, 5:46:48 AM4/14/20
to discuss-webrtc
Dear Roman, thank you for your answer. I do indeed have a relative path for compuleUnit (e.g. for webrtc::CreatePeerConnectionFactory):

 CompileUnit: id = {0x00000000}, file = "../../../api/create_peerconnection_factory.cc", language = "c++14"

      Function: id = {0x600002390}, name = "webrtc::CreatePeerConnectionFactory(rtc::Thread*, rtc::Thread*, rtc::Thread*, rtc::scoped_refptr<webrtc::AudioDeviceModule>, rtc::scoped_refptr<webrtc::AudioEncoderFactory>, rtc::scoped_refptr<webrtc::AudioDecoderFactory>, std::__1::unique_ptr<webrtc::VideoEncoderFactory, std::__1::default_delete<webrtc::VideoEncoderFactory> >, std::__1::unique_ptr<webrtc::VideoDecoderFactory, std::__1::default_delete<webrtc::VideoDecoderFactory> >, rtc::scoped_refptr<webrtc::AudioMixer>, rtc::scoped_refptr<webrtc::AudioProcessing>)", mangled = "_ZN6webrtc27CreatePeerConnectionFactoryEPN3rtc6ThreadES2_S2_NS0_13scoped_refptrINS_17AudioDeviceModuleEEENS3_INS_19AudioEncoderFactoryEEENS3_INS_19AudioDecoderFactoryEEENSt3__110unique_ptrINS_19VideoEncoderFactoryENSA_14default_deleteISC_EEEENSB_INS_19VideoDecoderFactoryENSD_ISG_EEEENS3_INS_10AudioMixerEEENS3_INS_15AudioProcessingEEE", range = [0x0000000100009250-0x00000001000096d7)


Unfortunately the remapping had no effect. I ran the following command in the Xcode console while paused on a breakpoint:

(lldb) settings set target.source-map . /absolute/path/to/webrtc_checkout/src/


Am I missing something?
One other thing I noticed is that the lookup gave me also the CreatePeerConnectionFactory symbol defined in the libwbrtc.dylib that is included in WebKit frameworks under System/Library . Could that also be an issue?
Thanks

Roman Gaiu

unread,
Apr 14, 2020, 12:43:11 PM4/14/20
to discuss-webrtc
Based on path in CompileUnit you can figure out what was working directory for compilation step, as example it could be <webrtc_src>/out/debug.
After that you can use that working directory for remapping:
(lldb) settings set target.source-map . <absolute path to working directory>

System libwbrtc.dylib should not be an issue.

Stefano Bider

unread,
Apr 14, 2020, 5:54:45 PM4/14/20
to discuss-webrtc
Thank you, I was in fact setting the wrong absolute path. Now I see the actual source instead of machine code. However, debugging still isn’t working fully. Breakpoints in any webrtc source file won’t work and call stack does not show up properly either (e.g cannot see the callers to any webrtc function). Again, my project includes the gn-generate xcode project (products.xcodeproj) as subproject.
Thank you for the help!

Stefano

Jose Antonio Olivera Ortega

unread,
Sep 17, 2020, 5:10:12 AM9/17/20
to discuss-webrtc
There is a GN flag (strip_absolute_paths_from_debug_symbols_default) you can change the default value for macOS so you do not need to set the mapping when running lldb. Go and edit src/build/config/compiler/compiler.gni. For macOS is true by default. Set false for it and you will see a absolute path for CompileUnit.

zouguowei

unread,
Dec 4, 2021, 2:50:50 PM12/4/21
to discuss-webrtc
I try above method, it works. Thanks 
Reply all
Reply to author
Forward
0 new messages