14
14
static luf_func_t * LoadFunction (luac_file_t * cf , tio_t * tio , size_t id );
15
15
16
16
static void LoadBlock (tio_t * t , void * b , size_t size ) {
17
- memcpy (b , t -> ptr , size );
17
+ memcpy (( char * ) b , t -> ptr , size );
18
18
t -> ptr += size ;
19
19
}
20
20
@@ -127,7 +127,7 @@ static void LoadConstants (tio_t *tio, luac_file_t* cf, luf_func_t *f) {
127
127
case LUA_TLNGSTR :
128
128
rpt -> strs .data [rpt -> strs .count ].data = LoadString (tio , & len );
129
129
rpt -> strs .data [rpt -> strs .count ].len = len ;
130
- rpt -> strs .data [rpt -> strs .count ].type = LUA_TLNGSTR ;
130
+ rpt -> strs .data [rpt -> strs .count ].type = t ;
131
131
f -> k [i ] = & rpt -> strs .data [rpt -> strs .count ];
132
132
rpt -> strs .count ++ ;
133
133
break ;
@@ -150,20 +150,12 @@ static void LoadUpvalues (tio_t *tio, luac_file_t* cf, luf_func_t *f) {
150
150
}
151
151
f -> upvalues = luat_heap_malloc (n * sizeof (lu_byte ) * 2 );
152
152
LoadBlock (tio , f -> upvalues , n * sizeof (lu_byte ) * 2 );
153
- // LLOGD("upvalue数量 %d", n);
154
- // for (i = 0; i < n; i++) {
155
- // // f->upvalues[i].instack = LoadByte(S);
156
- // // f->upvalues[i].idx = LoadByte(S);
157
- // f->upvalues[i*2] = LoadByte(tio);
158
- // f->upvalues[i*2 + 1] = LoadByte(tio);
159
- // }
160
153
}
161
154
162
155
static void LoadProtos (tio_t * tio , luac_file_t * cf , luf_func_t * f ) {
163
156
int i ;
164
157
int n = LoadInt (tio );
165
158
f -> sizep = n ;
166
- // LLOGD("子函数数量 %d", n);
167
159
for (i = 0 ; i < n ; i ++ ) {
168
160
f -> p [i ] = LoadFunction (cf , tio , cf -> report -> func_count );
169
161
}
@@ -201,6 +193,7 @@ static void LoadDebug (tio_t *tio, luac_file_t *cf, luf_func_t *f) {
201
193
// 变量名称
202
194
rpt -> strs .data [rpt -> strs .count ].data = LoadString (tio , & len );
203
195
rpt -> strs .data [rpt -> strs .count ].len = len ;
196
+ rpt -> strs .data [rpt -> strs .count ].type = len <= 41 ? LUA_TSTRING : LUA_TLNGSTR ;
204
197
f -> locvars2 [i ] = & rpt -> strs .data [rpt -> strs .count ];
205
198
rpt -> strs .count ++ ;
206
199
f -> locvars [i * 2 ] = LoadInt (tio );
@@ -215,6 +208,7 @@ static void LoadDebug (tio_t *tio, luac_file_t *cf, luf_func_t *f) {
215
208
for (i = 0 ; i < n ; i ++ ) {
216
209
rpt -> strs .data [rpt -> strs .count ].data = LoadString (tio , & len );
217
210
rpt -> strs .data [rpt -> strs .count ].len = len ;
211
+ rpt -> strs .data [rpt -> strs .count ].type = len <= 41 ? LUA_TSTRING : LUA_TLNGSTR ;
218
212
f -> upvalues2 [i ] = & rpt -> strs .data [rpt -> strs .count ];
219
213
rpt -> strs .count ++ ;
220
214
// LLOGD("debug信息: upvalue变量名长度 %d", len);
@@ -234,7 +228,7 @@ static luf_func_t * LoadFunction(luac_file_t *cf, tio_t* tio, size_t id) {
234
228
// char* tmp = NULL;
235
229
rpt -> strs .data [rpt -> strs .count ].data = LoadString (tio , & len );
236
230
rpt -> strs .data [rpt -> strs .count ].len = len ;
237
- rpt -> strs .data [rpt -> strs .count ].type = LUA_TSTRING ;
231
+ rpt -> strs .data [rpt -> strs .count ].type = len <= 41 ? LUA_TSTRING : LUA_TLNGSTR ;
238
232
f -> source = & rpt -> strs .data [rpt -> strs .count ];
239
233
rpt -> strs .count ++ ;
240
234
// f->source = LoadString(S, f);
@@ -249,8 +243,8 @@ static luf_func_t * LoadFunction(luac_file_t *cf, tio_t* tio, size_t id) {
249
243
rpt -> codes .data [rpt -> codes .count ].data = LoadCode (tio , & len );
250
244
rpt -> codes .data [rpt -> codes .count ].len = len ;
251
245
f -> code = & rpt -> codes .data [rpt -> codes .count ];
252
- f -> sizecode = len ;
253
- // LLOGD("函数[%d]代码大小 %d", id, len / 4 );
246
+ f -> sizecode = len / 4 ;
247
+ // LLOGD("函数[%d]代码大小 %d", id, len);
254
248
rpt -> codes .count ++ ;
255
249
// cf->g_report->func_count ++;
256
250
@@ -260,29 +254,12 @@ static luf_func_t * LoadFunction(luac_file_t *cf, tio_t* tio, size_t id) {
260
254
// LLOGD("啥情况");
261
255
LoadDebug (tio , cf , f );
262
256
// LLOGD("啥情况2");
263
-
264
- if (f -> sizep ) {
265
- // LLOGD("存在子函数 %d", f->sizep);
266
- // f->p = luat_heap_malloc(sizeof(void*) * f->sizep);
267
- // memset(f->p, 0, sizeof(void*) * f->sizep);
268
- // LLOGD("函数信息 id=%d %p", id, &cf->report->luf_funcs[id]);
269
- // LLOGD("函数信息 id=%d %p", id+1, &cf->report->luf_funcs[id+1]);
270
- for (size_t i = 0 ; i < f -> sizep ; i ++ )
271
- {
272
- // LLOGD("设置函数引用 %d %p %p %p %p", i, f, f->p[i], &cf->report->luf_funcs[id], &cf->report->luf_funcs[id + i]);
273
- // f->p[i] = &cf->report->luf_funcs[id + i + 1];
274
- // LLOGD("子函数关联 %-2d -> %-2d", id + i + 1, id);
275
- }
276
- }
277
- else {
278
- // LLOGD("没有子函数了");
279
- }
280
257
// LLOGD("===================<<<< %d", id);
281
258
return f ;
282
259
}
283
260
284
261
int luadb_do_report_file (luac_file_t * cf , const char * data ) {
285
- LLOGD ("分析文件%s %p" , cf -> source_file , data );
262
+ // LLOGD("分析文件%s %p", cf->source_file, data);
286
263
// char tmpbuff[8] = {0};
287
264
const char * ptr = data ;
288
265
// 首先, 分析头部
@@ -329,7 +306,7 @@ int luadb_do_report_file(luac_file_t *cf, const char* data) {
329
306
ptr ++ ;
330
307
331
308
332
- tio_t tio = {.ptr = ptr };
309
+ tio_t tio = {.ptr = ptr , . begin = ptr };
333
310
LoadFunction (cf , & tio , 0 );
334
311
335
312
// LLOGD("分析完成");
@@ -448,15 +425,6 @@ int luadb_do_report(luat_luadb2_ctx_t *ctx) {
448
425
cfs [i ].report = & rpts [i ];
449
426
cfs [i ].ptr = ctx -> fs -> files [i ].ptr ;
450
427
luadb_do_report_file (& cfs [i ], ctx -> fs -> files [i ].ptr );
451
-
452
- // 函数数据检查
453
- for (size_t i = 0 ; i < 1024 ; i ++ )
454
- {
455
- // if (cfs[i].report->luf_funcs[i].sizek){
456
- // LLOGD("函数数据 %d 存在, 指针位置: 0x%p", i, &cfs[i].report->luf_funcs[i] );
457
- // }
458
- }
459
-
460
428
}
461
429
else {
462
430
LLOGD ("跳过非lua文件 %s" , ctx -> fs -> files [i ].name );
@@ -486,16 +454,16 @@ int luadb_do_report(luat_luadb2_ctx_t *ctx) {
486
454
for (size_t i = 0 ; i < ctx -> fs -> filecount ; i ++ )
487
455
{
488
456
if (cfs [i ].report ) {
489
- luat_luf_toluac (& cfs [i ]);
457
+ // luat_luf_toluac(&cfs[i]);
490
458
}
491
459
}
492
-
460
+ luac_to_luf ( & cfs [ 0 ], ctx -> fs -> filecount , report );
493
461
494
462
// LLOGD("==============================================================");
495
463
// LLOGD(" 分类汇总报告");
496
464
// LLOGD("==============================================================\r\n");
497
465
// 分类报告
498
-
466
+ #if 0
499
467
// 文件信息表格
500
468
size_t file_max_len = 0 ;
501
469
size_t file_total_len = 0 ;
@@ -523,22 +491,22 @@ int luadb_do_report(luat_luadb2_ctx_t *ctx) {
523
491
// LLOGD("| %-30s | %6d | %s |", "==avg==", file_total_len / (ctx->fs->filecount > 0 ? ctx->fs->filecount : 1), "平均");
524
492
LLOGD ("==============================================================\r\n" );
525
493
526
- // luac_data_report_print_group(cfs, ctx->fs->filecount, report, 0, "字符串/二进制数据统计");
527
- // luac_data_report_print_group(cfs, ctx->fs->filecount, report, 1, "函数代码统计");
494
+ luac_data_report_print_group (cfs , ctx -> fs -> filecount , report , 0 , "字符串/二进制数据统计" );
495
+ luac_data_report_print_group (cfs , ctx -> fs -> filecount , report , 1 , "函数代码统计" );
528
496
// luac_data_report_print_group(cfs, ctx->fs->filecount, report, 2, "常量数值统计");
529
497
// luac_data_report_print_group(cfs, ctx->fs->filecount, report, 3, "upvalue统计");
530
498
// luac_data_report_print_group(cfs, ctx->fs->filecount, report, 4, "代码行数映射信息统计");
531
499
532
500
// 打印一下函数对象
533
- size_t func_count = 0 ;
534
- for (size_t i = 0 ; i < 1024 ; i ++ )
535
- {
536
- if (report -> luf_funcs [i ].sizecode > 0 ) {
537
- func_count ++ ;
538
- }
539
- }
501
+ // size_t func_count = 0;
502
+ // for (size_t i = 0; i < 1024; i++)
503
+ // {
504
+ // if (report->luf_funcs[i].sizecode > 0) {
505
+ // func_count ++;
506
+ // }
507
+ // }
540
508
// LLOGD("函数实例的总数 %d %d", func_count, report->func_count);
541
-
542
-
509
+ #endif
510
+ LLOGD ( "ALL Done" );
543
511
return 0 ;
544
512
}
0 commit comments