@@ -10,86 +10,86 @@ const SYMBOLS_BY_SECTION_FROM_ELF = "symbolsBySectionFromElf";
1010// Test the analyzer with local files
1111export async function handleElf ( context : vscode . ExtensionContext , panel : vscode . WebviewPanel ) {
1212
13- // 1. 先判断是否存在工作区
14- if ( ! vscode . workspace . workspaceFolders ) {
15- // 提示用户打开工作区
16- vscode . window . showErrorMessage ( '请先打开一个项目文件夹或工作区!' ) ;
17- return ;
18- }
19- const projectPath = vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath ;
20- const elfPath = path . join ( projectPath , 'rtthread.elf' ) ;
21- const mapPath = path . join ( projectPath , 'rtthread.map' ) ;
13+ // 1. 先判断是否存在工作区
14+ if ( ! vscode . workspace . workspaceFolders ) {
15+ // 提示用户打开工作区
16+ vscode . window . showErrorMessage ( '请先打开一个项目文件夹或工作区!' ) ;
17+ return ;
18+ }
19+ const projectPath = vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath ;
20+ const elfPath = path . join ( projectPath , 'rtthread.elf' ) ;
21+ const mapPath = path . join ( projectPath , 'rtthread.map' ) ;
2222
23- // Check if files exist
24- const elfExists = fs . existsSync ( elfPath ) ;
25- const mapExists = fs . existsSync ( mapPath ) ;
23+ // Check if files exist
24+ const elfExists = fs . existsSync ( elfPath ) ;
25+ const mapExists = fs . existsSync ( mapPath ) ;
2626
27- if ( ! elfExists && ! mapExists ) {
28- console . log ( '\nPlease place rtthread.elf and/or rtthread.map in the current directory to test.' ) ;
29- vscode . window . showInformationMessage ( 'ELF 或 MAP 文件不存在!请检查当前目录下是否存在 rtthread.elf 和 rtthread.map 文件' ) ;
30- return ;
31- }
27+ if ( ! elfExists && ! mapExists ) {
28+ console . log ( '\nPlease place rtthread.elf and/or rtthread.map in the current directory to test.' ) ;
29+ vscode . window . showInformationMessage ( 'ELF 或 MAP 文件不存在!请检查当前目录下是否存在 rtthread.elf 和 rtthread.map 文件' ) ;
30+ return ;
31+ }
3232
33- try {
34- const analyzer = new ElfAnalyzer (
35- elfExists ? elfPath : undefined ,
36- mapExists ? mapPath : undefined
37- ) ;
33+ try {
34+ const analyzer = new ElfAnalyzer (
35+ elfExists ? elfPath : undefined ,
36+ mapExists ? mapPath : undefined
37+ ) ;
3838
39- // Test getSections
40- const sections = analyzer . getSections ( ) ;
41- const postSections = [ ] ;
42- for ( let i = 0 ; i < sections . length ; i ++ ) {
43- const section = sections [ i ] ;
44- const symbols = analyzer . getSymbolsBySection ( section . name ) ;
45- if ( symbols . length > 0 ) {
46- postSections . push ( section ) ;
47- }
48- }
49- console . log ( '\n=== Sections (Top 5) ===' , postSections ) ;
50- panel . webview . postMessage ( { eventName : SECTIONS , data : postSections , from : 'extension' } ) ;
39+ // Test getSections
40+ const sections = analyzer . getSections ( ) ;
41+ const postSections = [ ] ;
42+ for ( let i = 0 ; i < sections . length ; i ++ ) {
43+ const section = sections [ i ] ;
44+ const symbols = analyzer . getSymbolsBySection ( section . name ) ;
45+ if ( symbols . length > 0 ) {
46+ postSections . push ( section ) ;
47+ }
48+ }
49+ console . log ( '\n=== Sections (Top 5) ===' , postSections ) ;
50+ panel . webview . postMessage ( { eventName : SECTIONS , data : postSections , from : 'extension' } ) ;
5151
52- // 监听 Webview 发送的消息
53- panel . webview . onDidReceiveMessage (
54- ( message ) => {
55- // 根据消息中的 command 处理不同逻辑
56- switch ( message . eventName ) {
57- case SYMBOLS_BY_SECTION :
58- const symbols = analyzer . getSymbolsBySection ( message . sectionName ) ;
59- panel . webview . postMessage ( { eventName : SYMBOLS_BY_SECTION_FROM_ELF , data : symbols , from : 'extension' } ) ;
60- default :
61- break ;
52+ // 监听 Webview 发送的消息
53+ panel . webview . onDidReceiveMessage (
54+ ( message ) => {
55+ // 根据消息中的 command 处理不同逻辑
56+ switch ( message . eventName ) {
57+ case SYMBOLS_BY_SECTION :
58+ const symbols = analyzer . getSymbolsBySection ( message . sectionName ) ;
59+ panel . webview . postMessage ( { eventName : SYMBOLS_BY_SECTION_FROM_ELF , data : symbols , from : 'extension' } ) ;
60+ default :
61+ break ;
62+ }
63+ } ,
64+ undefined , // 可选的错误处理
65+ ) ;
66+
67+ // Test getSymbolsBySection
68+ if ( elfExists ) {
69+ const sections = analyzer . getSections ( ) ;
70+ const textSection = sections . find ( s => s . name === '.text' ) ;
71+ if ( textSection ) {
72+ const textSymbols = analyzer . getSymbolsBySection ( '.text' ) ;
73+ }
6274 }
63- } ,
64- undefined , // 可选的错误处理
65- ) ;
6675
67- // Test getSymbolsBySection
68- if ( elfExists ) {
69- const sections = analyzer . getSections ( ) ;
70- const textSection = sections . find ( s => s . name === '.text' ) ;
71- if ( textSection ) {
72- const textSymbols = analyzer . getSymbolsBySection ( '.text' ) ;
73- }
74- }
76+ // Test getSymbols by object (if MAP file available)
77+ if ( mapExists ) {
78+ const allSymbols = analyzer . getAllSymbols ( ) ;
79+ const uniqueObjects = new Set ( allSymbols . map ( s => s . object ) . filter ( o => o ) ) ;
80+ const firstObject = Array . from ( uniqueObjects ) [ 0 ] ;
7581
76- // Test getSymbols by object (if MAP file available)
77- if ( mapExists ) {
78- const allSymbols = analyzer . getAllSymbols ( ) ;
79- const uniqueObjects = new Set ( allSymbols . map ( s => s . object ) . filter ( o => o ) ) ;
80- const firstObject = Array . from ( uniqueObjects ) [ 0 ] ;
82+ if ( firstObject ) {
83+ console . log ( `\n=== Symbols in ${ firstObject } (Top 5) ===` ) ;
84+ const objectSymbols = analyzer . getSymbols ( firstObject ) ;
85+ console . log ( `Found ${ objectSymbols . length } symbols:` ) ;
86+ objectSymbols . slice ( 0 , 5 ) . forEach ( symbol => {
87+ console . log ( ` ${ symbol . name } : size=${ symbol . size } , addr=${ symbol . hexaddr } ` ) ;
88+ } ) ;
89+ }
90+ }
8191
82- if ( firstObject ) {
83- console . log ( `\n=== Symbols in ${ firstObject } (Top 5) ===` ) ;
84- const objectSymbols = analyzer . getSymbols ( firstObject ) ;
85- console . log ( `Found ${ objectSymbols . length } symbols:` ) ;
86- objectSymbols . slice ( 0 , 5 ) . forEach ( symbol => {
87- console . log ( ` ${ symbol . name } : size=${ symbol . size } , addr=0x${ symbol . address . toString ( 16 ) } ` ) ;
88- } ) ;
89- }
92+ } catch ( error ) {
93+ console . error ( 'Error during analysis:' , error ) ;
9094 }
91-
92- } catch ( error ) {
93- console . error ( 'Error during analysis:' , error ) ;
94- }
9595}
0 commit comments