WindhoverLabs / juicer

5 stars 0 forks source link

Macros Quirks and Issues #35

Closed lorenzo-gomez-windhover closed 1 month ago

lorenzo-gomez-windhover commented 2 months ago

When redefining a macro like this:

#define CFE_MISSION_ES_PERF_MAX_IDS 128
#define CFE_MISSION_ES_PERF_MAX_IDS 160

For some reason that macro does not appear to be in the DWARF section anymore.

Tested this with:

Some links of interest:

lorenzo-gomez-windhover commented 1 month ago

Another quirk: I'm currently using dwarfdump "2020-01-14 10:13:32-08:00 Package Version "20200114"" to look at macros inside the DWARF.

Imagine two files; test_file1.h and test_file1.cpp

test_file1.cpp is defined as follows:

    /*
     * test_file.cpp
     *
     */

    #ifdef __cplusplus
    extern "C" {
    #endif

    #include "test_file1.h"

    #include <fcntl.h>
    #include <stdio.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <unistd.h>

    #ifdef __cplusplus
    }
    #endif

Here are two scenarios for the definition of test_file1.h.

Scenario #1

test_file.h is defined as follows:

    #include "stdint.h"

    #define CFE_MISSION_ES_PERF_MAX_IDS 128

    typedef struct CFE_ES_HousekeepingTlm_Payload
    {
        uint32_t PerfFilterMask[CFE_MISSION_ES_PERF_MAX_IDS / 32];  /**< \cfetlmmnemonic \ES_PERFFLTRMASK
                                                               \brief Current Setting of Performance Analyzer Filter Masks */
        uint32_t PerfTriggerMask[CFE_MISSION_ES_PERF_MAX_IDS / 32]; /**< \cfetlmmnemonic \ES_PERFTRIGMASK
                                                                 \brief Current Setting of Performance Analyzer Trigger Masks */
    } CFE_ES_HousekeepingTlm_Payload_t;

After compiling with "gcc -g3 -c -gdwarf-4 test_file1.cpp -o test_file1_copy_dwarf4.o" and then running "dwarfdump test_file1_dwarf4.o > dwarf4_test_file1.txt". The Macro doe NOT show up in dwarf4_test_file1.txt. It does show up under the debug string table but not under the "debug_macro" section.

Scenario #2

test_file.h is defined as follows:


        #define CFE_MISSION_ES_PERF_MAX_IDS 128

    #include "stdint.h"

    typedef struct CFE_ES_HousekeepingTlm_Payload
    {
        uint32_t PerfFilterMask[CFE_MISSION_ES_PERF_MAX_IDS / 32];  /**< \cfetlmmnemonic \ES_PERFFLTRMASK
                                                               \brief Current Setting of Performance Analyzer Filter Masks */
        uint32_t PerfTriggerMask[CFE_MISSION_ES_PERF_MAX_IDS / 32]; /**< \cfetlmmnemonic \ES_PERFTRIGMASK
                                                                 \brief Current Setting of Performance Analyzer Trigger Masks */
    } CFE_ES_HousekeepingTlm_Payload_t;

After compiling with "gcc -g3 -c -gdwarf-4 test_file1.cpp -o test_file1_dwarf4.o" and then running "dwarfdump test_file1_dwarf4.o > dwarf4_test_file1.txt". The Macro DOES show up in dwarf4_test_file1.txt. It does show up under the "debug_macro" section.

Is there a reason why in order for macros to show up they have to be declared before the #include macro(s)?

If I link the "test_file1.o" file with "gcc -g3 -nostartfiles -Llib -gdwarf-4 test_file1_copy.o -o test_file1_linked_dwarf4.o" the macro shows up in the DWARF, regardless of whether it is defined before/after the #include.

lorenzo-gomez-windhover commented 1 month ago

Learned a few things going down this rabbit hole. This mailing list thread for DWARF STD ought to be informative for anyone curious about more details.

lorenzo-gomez-windhover commented 1 month ago

https://gcc.gnu.org/wiki/DebugFissionDWP https://gcc.gnu.org/wiki/DebugFission https://reviews.llvm.org/D82975 https://maskray.me/blog/2022-10-30-distribution-of-debug-information