簡體   English   中英

強制相對調試符號路徑(maven-native-plugin)

[英]Force relative debug symbol path (maven-native-plugin)

我使用native-maven-plugin在linux上編譯共享庫。 我傳遞編譯器選項-g以啟用調試符號生成。 以下是POM的摘錄:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <workingDirectory></workingDirectory>
                <compilerStartOptions>
                    <compilerStartOption>-g</compilerStartOption>
                </compilerStartOptions>
                <linkerStartOptions>
                    <linkerStartOption>-shared</linkerStartOption>
                    <linkerStartOption>-g</linkerStartOption>
                </linkerStartOptions>
                <sources>
                    ...
                </sources>
            </configuration>
        </plugin> 

native-maven-plugin在調用gcc時會使用源文件的絕對路徑。 這也導致調試符號中的絕對路徑。 列出調試符號的nm -l libfoo.so的輸出如下所示:

0000797a T GetTickCount /home/myusername/projects/blabla/foo.c:3005

如您所見,源文件路徑是絕對路徑,包括我的用戶名和項目結構。 我不希望這樣。 如何將調試符號更改為相對路徑名?

好吧,我發現gcc中有一個-fdebug-prefix-map=oldPath=newPath選項,它完全符合我的要求。 要從我的問題編譯文件/home/myusername/projects/blabla/foo.c

gcc -fdebug-prefix-map=/home/myusername/projects/blabla=theNewPathInDebug -o foo.o foo.c
gcc -shared -o libfoo.so foo.o

然后調試符號路徑看起來像( nm -l libfoo.so ):

0000797a T GetTickCount theNewPathInDebug/foo.c:3005

然后,您可以使用gdb路徑替換來設置gdb的實際源文件位置。

為了讓一切都在maven中工作,我的pom看起來像:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <extensions>true</extensions>
        <configuration>
            <workingDirectory></workingDirectory>
            <compilerStartOptions>
                <compilerStartOption>-g</compilerStartOption>
                <compilerStartOption>-fdebug-prefix-map=${project.build.directory}/extracted-c=theNewPathInDebug</compilerStartOption>
            </compilerStartOptions>
            <linkerStartOptions>
                <linkerStartOption>-shared</linkerStartOption>
                <linkerStartOption>-g</linkerStartOption>
            </linkerStartOptions>
            <sources>
                <source>
                    <directory>${project.build.directory}/extracted-c</directory>
                    <fileNames>
                        <fileName>foo.c</fileName>
                    </fileNames>
                </source>
            </sources>
        </configuration>
    </plugin> 

其中extract -cmaven-dependency-plugin提取C源/頭文件的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM