Skip to content

Commit 80872f5

Browse files
author
sunxianfu
committed
feat: 优化交互
1 parent 729b101 commit 80872f5

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/utils/elf/elf-parser.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ElfParser {
99
private symbolTable!: Buffer;
1010
private symbolStringTable!: Buffer;
1111
private is64Bit: boolean = false;
12+
private symbols: Symbol[] = [];
1213

1314
constructor(filePath: string) {
1415
this.buffer = fs.readFileSync(filePath);
@@ -146,7 +147,7 @@ export class ElfParser {
146147
}
147148

148149
private getSectionName(index: number): string {
149-
if (!this.stringTable) return '';
150+
if (!this.stringTable) {return '';}
150151
return this.getString(this.stringTable, index);
151152
}
152153

@@ -169,6 +170,9 @@ export class ElfParser {
169170
}
170171

171172
public getAllSymbols(): Symbol[] {
173+
if(this.symbols.length > 0) {
174+
return this.symbols;
175+
}
172176
if (!this.symbolTable || !this.symbolStringTable) {
173177
return [];
174178
}
@@ -202,10 +206,10 @@ export class ElfParser {
202206
}
203207

204208
const size = Number(entry.size);
205-
if (size === 0) continue; // Skip symbols with zero size
209+
if (size === 0) {continue;} // Skip symbols with zero size
206210

207211
const name = this.getString(this.symbolStringTable, entry.name);
208-
if (!name) continue;
212+
if (!name) {continue;}
209213

210214
const type = this.getSymbolType(entry.info);
211215
const sectionName = this.getSectionNameByIndex(entry.shndx);
@@ -219,7 +223,9 @@ export class ElfParser {
219223
});
220224
}
221225

222-
return symbols.sort((a, b) => b.size - a.size);
226+
227+
this.symbols = symbols.sort((a, b) => b.size - a.size);
228+
return this.symbols;
223229
}
224230

225231
public getSymbolsBySection(sectionName: string): Symbol[] {

src/utils/elf/handleElf.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export async function handleElf(context: vscode.ExtensionContext, panel: vscode.
2020
const elfPath = path.join(projectPath, 'rtthread.elf');
2121
const mapPath = path.join(projectPath, 'rtthread.map');
2222

23-
console.log('\n==========================================');
24-
2523
// Check if files exist
2624
const elfExists = fs.existsSync(elfPath);
2725
const mapExists = fs.existsSync(mapPath);
@@ -40,12 +38,20 @@ export async function handleElf(context: vscode.ExtensionContext, panel: vscode.
4038

4139
// Test getSections
4240
const sections = analyzer.getSections();
43-
panel.webview.postMessage({ eventName: SECTIONS, data: sections, from: 'extension' });
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' });
4451

4552
// 监听 Webview 发送的消息
4653
panel.webview.onDidReceiveMessage(
4754
(message) => {
48-
console.log('Received message:', message);
4955
// 根据消息中的 command 处理不同逻辑
5056
switch (message.eventName) {
5157
case SYMBOLS_BY_SECTION:

src/vue/analyze/App.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="container">
33
<Banner sub-title="分析" />
44

5-
<div>
5+
<div class="content_area">
66
<el-tabs
77
v-model="activeName"
88
class="demo-tabs"
@@ -13,7 +13,8 @@
1313
:label="item.name"
1414
:name="item.name"
1515
>
16-
<el-table :data="tableData" style="width: 100%">
16+
<el-table :data="tableData" style="width: 100%" v-loading="tableLoading" >
17+
">
1718
<el-table-column
1819
v-for="item in tableColumns"
1920
:prop="item.prop"
@@ -45,7 +46,7 @@ const SYMBOLS_BY_SECTION_FROM_ELF = "symbolsBySectionFromElf";
4546
4647
const activeName = ref();
4748
48-
49+
const tableLoading = ref(true);
4950
5051
const tableColumns = [
5152
{
@@ -58,7 +59,7 @@ const tableColumns = [
5859
},
5960
{
6061
label: "地址",
61-
prop: "addr",
62+
prop: "address",
6263
},
6364
{
6465
label: "大小",
@@ -79,6 +80,7 @@ const handleSentMessage = (sectionName: string) => {
7980
};
8081
8182
const handleVChanged = (name: TabPaneName) => {
83+
tableLoading.value = true;
8284
handleSentMessage(`${name}`)
8385
};
8486
@@ -99,6 +101,7 @@ onMounted(() => {
99101
break;
100102
101103
case SYMBOLS_BY_SECTION_FROM_ELF:
104+
tableLoading.value = false;
102105
tableData.value = message.data;
103106
break;
104107
default:
@@ -112,6 +115,7 @@ onMounted(() => {
112115
.container {
113116
padding: 0;
114117
background-color: #fff;
118+
min-height: 100vh;
115119
}
116120
117121
.demo-tabs > .el-tabs__content {

0 commit comments

Comments
 (0)