Can source server (Debugging Tools for Windows) be used with static library projects? - static

I can't find a way to use the source server tools from the Debugging Tools for Windows on a static library project,
which is built separately from the solutions actually using that library:
The output of "ssindex.cmd" always displays "zero source files found" for the PDB file generated for the library
(using compiler options /ZI and /Fd).
Running "srctool.exe -r" on this PDB displays nothing, which probably means that the PDB file does not contain any source file information.
Running the same command on the PDB file of a test application which is also build as part of the the same solution
yields a list of all expected source files.
Is there a way to use source indexing for a static library project when it should be built seperately from the solutions using it?
Thanks for any suggestions!

You can use the "/Save" and "/Load" options to store and load source information for a static library, respectively. Using these options allows you to store information for your library and then later import it when indexing a project that links against your library.
When indexing your library solution, you specify the "/Save" flag with a directory in which to store index information about the library's source files. For example (assuming you are using Subversion for source control),
ssindex.cmd /System=SVN /Save=c:\source\libproj\srcinfo /Source=c:\source\libproj /Symbols=c:\source\libproj\Release\*.pdb
When later indexing your project that includes your library, you specify the "/Load" flag with the directory containing the library's source file information. For example,
ssindex.cmd /System=SVN /Load=c:\source\libproj\srcinfo /Source=c:\source\binproj /Symbols=c:\source\binproj\Release\*.pdb
There are two potential issues that may affect your ability to use this technique. First, it appears that some source control providers may not support saving and loading source control information. I know that the Subversion provider does and it looks like the SourceSafe provider does, but I haven't checked any others.
Second, this technique appears to only work for one external static library out-of-the-box. There does not seem to be a way to load information from multiple directories and the scripts currently overwrite the contents of the directory each time you use the "/Save" option. You could probably edit the source control provider module to append to the files in the save directory rather than overwrite them, but I have not tried it.
Also, note as you mentioned above that you only need to do this if your library is being built as part of a separate solution. If the static library is part of the solution you are indexing, its source files will be included if they are in the path specified by the "/Source" option.

It probably means you haven't inputed the correct directories when running "ssindex" so for ssindex you need to have: /source=C:/SourceCode/ /symbols=C:/SourceCode/bin/Debug I'm not sure if the "source" has an upper case S or not but that should be it!

when run svnindex.cmd, it always tell you "zero source files found"
after a painful diggin into svn.pm (the perl module to deal with svn), i found that:
first, svn.pm invokes "svn info -R $SourceRoot" to get all version info of files in $SourceRoot (passed by /source option),
then svn.pm stores all files in a dictionary which using the local file path as key
svnindex.cmd call srctool -r to get all source files info in *.pdb, and use the source file name as a key to query info saved in step2
the problem is:
svn.pm uses relative path, but *.pdb uses absolute path, so you will never find a svn log info for any file, then "zero source files found"
fixup:
change svn.pm line 162:
$LocalFile = lc $1;
to   
$LocalFile = $SourceRoot . "\" . lc $1; #make path absolute

Related

How to cut (azure_iot_sdk_c) to facilitate porting to embedded Linux platform

I have successfully compiled (azure_iot_sdk_c) on Linux and successfully run this demo (iothub_ll_c2d_sample). Now, I want to extract the source code related to this demo to facilitate the migration to the embedded Linux platform. What should I do? The source code provided by Microsoft contains a lot of code unrelated to the Linux platform in order to be compatible with more platforms.
I tried to take out the source code in the sdk, delete the code of other platforms, and judge whether the platform is related by the file name, but it could not be compiled. I want to know what files are required for this demo (iothub_ll_c2d_sample) to run normally. I want to take them out and compile them separately, so that they can be ported to the embedded Linux platform.
You can extract the code sample file and compile it independently by importing the required header files for the code in iothub_ll_c2d_sample.c
Even though the code lists only six external reference files, some of the header files have internal dependencies. By back tracing, I found eighteen header files that are referenced by them. You would have to provide a local reference to all these files to make the code compile successfully. Please find the below image referring all the header files the program needs to compile.
You can get the header files from the below URLs
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/map.h
https://github.com/Azure/azure-iot-arduino-utility/blob/master/src/azure_c_shared_utility/azure_macro_utils/macro_utils.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_device_client_ll.h
https://github.com/Azure/azure-iot-arduino-utility/blob/master/src/azure_c_shared_utility/azure_macro_utils/macro_utils_generated.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_transport_ll.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_core_ll.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_core_common.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_message.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/strings.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/const_defines.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/strings_types.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothubtransportmqtt.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/shared_util_options.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/crt_abstractions.h
https://github.com/Azure/azure-c-shared-utility/blob/master/inc/azure_c_shared_utility/threadapi.h
https://github.com/Azure/umock-c/blob/master/inc/umock_c/umock_c_prod.h
https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/inc/iothub_client_options.h
Note that since I have the files under the same directory, I will no longer need to provide a relative path while referencing the header files in the program. I can directly access them as below
The same goes with the header files. I can directly refer the dependent header files without providing any relative path. Please find the below image of the iothub.h header file which refernces umock_c_prod.h file and notice there is no relative path.
If you decide to place the header files under a different directory, make sure to provide a relative path for the code to compile.

Change which file vscode opens when using "go to definition"

I'm using Visual Studio Code to manage a C project that contains a number of libraries and fully-linked executables. When the executables need to depend on headers from a library, rather that point at the library's source files directly, they point at a build directory containing the headers. That is, for a source layout like:
project/lib/src/lib.h
project/exe/src/exe.c
Rather than the build for project/exe including -I project/lib/src, it does -I project/lib/build, which will have a copy of lib.h in it from the last time the library was built. This is done for miscellaneous reasons that don't matter here, and mostly works fine, except when I use vscode's "Go to Definition" feature (F12, Ctrl+Click, etc.).
Because vscode is using the compiler's include path to know where to find headers, if I go to the definition of anything in lib.h, vscode will open project/lib/build/lib.h instead of project/lib/src/lib.h. Is there a way, either built-in or via a plugin, to hook vscode's belief that it should open project/lib/build/lib.h and change it to project/lib/src/lib.h? I'm even willing to write a plugin, but I couldn't find a way to either modify the language server's result to change the path, or intercept vscode attempting to open a particular path and change it on-demand.

Finding file locations in offline softwares in C

At some point in my C program I have to deal with something like this.
FILE * fptr = fopen("/Parent/child/.../file.dat");
Which means in order to access any file I need to know it's location. That's all understandable.
But, how can I make this generic? In my computer "/Parent/child/.../file.dat" will work because that's where the file is stored, but I'm making a software to distribute to other users so the path obviously differs. My question is, how can I install a specific file into the user's computer such that I can know and get the location of that file. I a but confused about this concept so any resources that could help me understand it better would be greatly appreciated.
In Linux the default path to application files should be hardcoded. There is a standard which applications should follow. For example, architecture-independent files should go to /usr/share/ and then either your application name or, if you expect the data to be shared between applications, a generic category such as images. User-specific configuration files should go $HOME/.config/<app-name>. Older applications place their default configuration in $HOME/.<app-name> instead.
You should also provide an ability to override the default path to the data with a command line switch and/or an environment variable and/or a user configuration file (the location of the latter should also be overridable with a command line switch and/or an environment variable).
Some applications search for their data directory relatively to the executable position. An executable can know its own absolute path by reading /proc/self/exe symbolic link. For example, if an executable finds itself in /usr/local/bin/somename, it can look for /usr/local/share/<app-name> (two levels up from the executable name and down to share/<app-name>.).
Finally, if you distribute source code for the users to build, the file locations should be configuration parameters.

How to include header AND source files folder in Visual Studio

I am using Visual Studio (2017) and I need the following.
I have a folder where a code generator puts the .h and .c files obtained from a formal model. This folder is not controlled by me, e.g. I cannot write in it, but it is updated by another team member.
By using the /I compiler options (or Additional include directories in the project properties) I managed to import all the generated header files in my VS project. What I am supposed to do is to integrate this generated code into a specific platform, this means that I have to compile both the generated code and the integration code on the target platform. The problem is, the compiler is not able to resolve the generated function definitions of the generated code as it only sees the .h files. What I got is a linking error (external symbol not resolved)
To solve the problem, I added the existing .c files manually, one by one. The obvious problems that comes with this solution are
manual boring work
when new files are generated, I need to manually import the new files
Question is: is there an option that can be set in order to specify the path of the source files without passing them one by one?
note: just copying and pasting the generated code in the VS project folder is not an acceptable solution.
Thanks
If you look at https://learn.microsoft.com/en-us/cpp/ide/working-with-project-properties?view=vs-2017 then you see there is a Source Directories property that has $(VC_SourcePath) as a default but (I think) to which you can add additional paths. The documentation is unclear whether that means all source files in such a path will be included for compilation.
At the bottom of the documentation it explains how to override certain project properties by providing an external properties file. It seems you can override the targets/sources using such a file. You can generate the file using a small tool that reads the filenames in those directories and adds them to the file.
You could also analyze the .vcproj file and build a small tool that wil re-write the part with your generated source directories, reading the filenames in those directories and adding them to the section in the .vcproj file.

How extract deployment files from MSI database

MSI database contains set of tables, and I can successfully enumerate File table, which has all deployable file' meta-deta. What I need to extract is the actual contents of those files. msiexec, lessmsi, 7-zip all can do it, but I couldn't find any source/API to do it.
What I've discovered it that all other (resource) files are in Binary table, and Data field can be used to get content of those files (like icons, custom DLL etc).
Further, I found and know that Media table contains information about the .CAB file (MSI has all content embedded with <MediaTemplate EmbedCab="yes"/>. This simply means the CAB file contains the actual content. I probably need to read contents from "Structured Storage" of the .msi file.
How to extract the contents of CAB/MSI file, using native C Msi* functions?
Phil has given you the easy/simple answer but I thought I might give you a little more information since you've done some research. Checkout:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa372919(v=vs.85).aspx
This is where the structured storage is. You'll see something like Disk1.cab as the Name (PK) and binary data. The data is a CAB file with the file entry in the cab matching the File.File column. From there you can use the File.FileName column to get the short name and long name (you'll want the long name no doubt) and do a joint to the Component table to get the directory table ID.
You'll also need to recurse the directory table to build the tree of directories and know where to put the files.
Fun stuff. There's some libraries in C# that make this WAY simpler. Or just call msiexec /a as Phil says. :)
The most straightforward to extract all the files to some location is to install the product in "advertised" mode. If you do a:
msiexec /a [path to msi] TARGETDIR=[some folder]
you'll see what happens.
In C++ call MsiInstallProduct () with that command line.
You have gotten many good answers already, including the use of dark.exe from the WiX toolkit. By downloading the WiX source code you should be able to get the code you need ready-made from there. I assume you may already have done this.
Chris has already linked to the DTF code you can check, but here is a link directly to dark.exe as well: https://github.com/wixtoolset/wix3/tree/develop/src/tools/dark. I would try both. This is C#, you seem to want native.
UPDATE: Before I get to the Win32 features you can use, check out this little summary of the C# DTF features: How to programmatically read the properties inside an MSI file?
Native Win32 functions: The database functions to deal with an MSI file can be found on MSDN (this is to deal with the MSI file as a database). There are also MSI Installer Functions (used to deal with the MSI file as an actual installer).
You can certainly find good examples of native code for this with a good Google search. Have fun!
BTW: It would help with a description of the actual problem you are trying to solve as well as what you need technically. There could - as always - be less involved ways to achieve what you need. Unless you are writing a security software or malware scanner or something super-involved.
And so it is clear: WiX's dark.exe fully decompiles MSI files into WiX source files and the resource files used to build them - you can then text and binary compare the various types of content (text compare for tables, binary compare for binaries, etc...). The process to do so via command line is described in the following answer: How can I compare the content of two (or more) MSI files? (this is about comparing MSI files, but one option to do so is to decompile them - see section on dark.exe - just for reference for others who find your question).
I like to link things together so we can find content easily at a later point in time. Strictly speaking it doesn't seem necessary here, you have what you need I think but others could perhaps benefit from some further links. Here are some related links:
Extract MSI from EXE.
What is the purpose of administrative installation initiated using msiexec /a?
How do I extract files from an MSI package? (explains why you should not use 7-Zip to extract).

Resources