0

For example, I have two projects let's say project A and project B. I have the source code of project A and project B.

Then in my project A, there are some .a files made by project B. Project A use those .a files to compile and run.

The question is, when I run project A, I want to debug the codes in those .a file. Is it possible? If possible, how can I do it?

I'm using Visual Studio for Mac.

Note: Project A is written in C# and Project B is written in C++.

It‘s a Xamarin project.

nevermore
  • 15,432
  • 1
  • 12
  • 30

4 Answers4

2

If you have no source code of project B, then you can only debug in assembly mode.

If you do have source code of project B, make sure .a files reserving debug info(like dwarf) and use lldb source-map technique to perform mapping.

But, if you have .a file's source, why not just build with project B source.

Kam
  • 51
  • 6
  • why not just build with project B source. Project A is written by C # and Project B is written by C ++. I have the source code, can you share me some documents or steps? – nevermore Sep 18 '21 at 08:12
  • @JackHua I haven't done this in practice. Maybe try this https://www.mono-project.com/docs/debug+profile/debug/lldb-source-map/ ? – Kam Sep 18 '21 at 08:23
0

You need to attach with Visual studio to the running process. Attaching to process with Visual Studio is done with Alt + Ctrl + P on windows.

In case the code you wish to debug is run at startup of your app, place your breakpoints and add a 30 seconds sleep (before any of your breakpoints) so you have time to attach.

When picking the process, make sure to tick the right code types to debug by clicking Select...

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
Cosmin Sontu
  • 1,034
  • 11
  • 16
  • Thanks for your answer, I can't find the process as it is a Xamarin project and it runs in a iPad. – nevermore Sep 27 '21 at 00:26
  • This is very imporant information since Xamarin debugging can be really problematic and some things might not work exactly as expected. You should add this note into the question. – Tatranskymedved Sep 27 '21 at 11:39
0

If you have access to source code for both projects, I would recommend to create a solution with both projects, as you may be able to use different language projects on same solution (please check this, as an example: https://social.msdn.microsoft.com/Forums/en-US/737e2bf3-86ab-49aa-bafa-b3a3d05ce826/mixed-languages-in-visual-studio?forum=csharpgeneral).

To debug C++ code inside the C# project, check options for your current Visual Studio version, as suggested in this post: Debug c++ dll in C#

Set project A (C#) as start project, and, if references are correct, you should be able to debug .a files referenced from project B.

Dave Miller
  • 536
  • 3
  • 19
0

You can build both Debug and Release into separate preset directories in any IDE. This is a good practice for all builds - using Configuration -> Release and Debug. You may name the libraries as libname_d.lib and libname.a so they do not get mixed up.

Then you can link to the appropriate library (libname_d.a) while debugging. Its a matter of choice - some may not recommend linking multiple projects into the same Solution (or Workspace), since each separate library will have a separate set of tests. These are difficult to manage in a single project.

Ideally, each library can be coded and tested separately and built into Release and Debug. This way functionality can be isolated and object-based design can be followed.

Its also important to understand the difference between .a (Linux, Mac) and .lib (Windows) - see here - What's the difference between .lib and .a files?

moi
  • 467
  • 4
  • 19