99#include "../../flamenco/runtime/fd_bank.h"
1010#include "../../flamenco/runtime/fd_runtime.h"
1111#include "../../flamenco/runtime/fd_acc_pool.h"
12+ #include "../../flamenco/runtime/tests/fd_dump_pb.h"
1213#include "../../flamenco/progcache/fd_progcache_user.h"
1314#include "../../flamenco/log_collector/fd_log_collector_base.h"
1415#include "../../disco/metrics/fd_metrics.h"
@@ -44,6 +45,10 @@ struct fd_execrp_tile {
4445 fd_capture_ctx_t * capture_ctx ;
4546 fd_capture_link_buf_t cap_execrp_out [1 ];
4647
48+ /* Protobuf dumping context for debugging runtime execution and
49+ collecting seed corpora. */
50+ fd_dump_proto_ctx_t * dump_proto_ctx ;
51+
4752 /* A transaction can be executed as long as there is a valid handle to
4853 a funk_txn and a bank. These are queried from fd_banks_t and
4954 fd_funk_t. */
@@ -275,11 +280,12 @@ unprivileged_init( fd_topo_t * topo,
275280 void * scratch = fd_topo_obj_laddr ( topo , tile -> tile_obj_id );
276281
277282 FD_SCRATCH_ALLOC_INIT ( l , scratch );
278- fd_execrp_tile_t * ctx = FD_SCRATCH_ALLOC_APPEND ( l , alignof(fd_execrp_tile_t ), sizeof (fd_execrp_tile_t ) );
279- void * capture_ctx_mem = FD_SCRATCH_ALLOC_APPEND ( l , fd_capture_ctx_align (), fd_capture_ctx_footprint () );
280- void * _txncache = FD_SCRATCH_ALLOC_APPEND ( l , fd_txncache_align (), fd_txncache_footprint ( tile -> execrp .max_live_slots ) );
281- uchar * pc_scratch = FD_SCRATCH_ALLOC_APPEND ( l , FD_PROGCACHE_SCRATCH_ALIGN , FD_PROGCACHE_SCRATCH_FOOTPRINT );
282- ulong scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI ( l , scratch_align () );
283+ fd_execrp_tile_t * ctx = FD_SCRATCH_ALLOC_APPEND ( l , alignof(fd_execrp_tile_t ), sizeof (fd_execrp_tile_t ) );
284+ void * capture_ctx_mem = FD_SCRATCH_ALLOC_APPEND ( l , fd_capture_ctx_align (), fd_capture_ctx_footprint () );
285+ void * dump_proto_ctx_mem = FD_SCRATCH_ALLOC_APPEND ( l , alignof(fd_dump_proto_ctx_t ), sizeof (fd_dump_proto_ctx_t ) );
286+ void * _txncache = FD_SCRATCH_ALLOC_APPEND ( l , fd_txncache_align (), fd_txncache_footprint ( tile -> execrp .max_live_slots ) );
287+ uchar * pc_scratch = FD_SCRATCH_ALLOC_APPEND ( l , FD_PROGCACHE_SCRATCH_ALIGN , FD_PROGCACHE_SCRATCH_FOOTPRINT );
288+ ulong scratch_alloc_mem = FD_SCRATCH_ALLOC_FINI ( l , scratch_align () );
283289
284290 if ( FD_UNLIKELY ( scratch_alloc_mem - (ulong )scratch - scratch_footprint ( tile ) ) ) {
285291 FD_LOG_ERR ( ( "Scratch_alloc_mem did not match scratch_footprint diff: %lu alloc: %lu footprint: %lu" ,
@@ -375,52 +381,51 @@ unprivileged_init( fd_topo_t * topo,
375381 /********************************************************************/
376382
377383 ctx -> capture_ctx = NULL ;
378-
379- if ( FD_UNLIKELY ( strlen ( tile -> execrp .solcap_capture ) || strlen ( tile -> execrp .dump_proto_dir ) ) ) {
384+ if ( FD_UNLIKELY ( strlen ( tile -> execrp .solcap_capture ) ) ) {
380385 ctx -> capture_ctx = fd_capture_ctx_join ( fd_capture_ctx_new ( capture_ctx_mem ) );
381386 ctx -> capture_ctx -> solcap_start_slot = tile -> execrp .capture_start_slot ;
382387
383- if ( strlen ( tile -> execrp .solcap_capture ) ) {
384- ulong tile_idx = tile -> kind_id ;
385- ulong idx = fd_topo_find_tile_out_link ( topo , tile , "cap_execrp" , tile_idx );
386- FD_TEST ( idx != ULONG_MAX );
387- fd_topo_link_t * link = & topo -> links [ tile -> out_link_id [ idx ] ];
388- fd_capture_link_buf_t * cap_execrp_out = ctx -> cap_execrp_out ;
389- cap_execrp_out -> base .vt = & fd_capture_link_buf_vt ;
390- cap_execrp_out -> idx = idx ;
391- cap_execrp_out -> mem = topo -> workspaces [ topo -> objs [ link -> dcache_obj_id ].wksp_id ].wksp ;
392- cap_execrp_out -> chunk0 = fd_dcache_compact_chunk0 ( cap_execrp_out -> mem , link -> dcache );
393- cap_execrp_out -> wmark = fd_dcache_compact_wmark ( cap_execrp_out -> mem , link -> dcache , link -> mtu );
394- cap_execrp_out -> chunk = cap_execrp_out -> chunk0 ;
395- cap_execrp_out -> mcache = link -> mcache ;
396- cap_execrp_out -> depth = fd_mcache_depth ( link -> mcache );
397- cap_execrp_out -> seq = 0UL ;
398-
399- ulong consumer_tile_idx = fd_topo_find_tile (topo , "solcap" , 0UL );
400- fd_topo_tile_t * consumer_tile = & topo -> tiles [ consumer_tile_idx ];
401- cap_execrp_out -> fseq = NULL ;
402- for ( ulong j = 0UL ; j < consumer_tile -> in_cnt ; j ++ ) {
403- if ( FD_UNLIKELY ( consumer_tile -> in_link_id [ j ] == link -> id ) ) {
404- cap_execrp_out -> fseq = fd_fseq_join ( fd_topo_obj_laddr ( topo , consumer_tile -> in_link_fseq_obj_id [ j ] ) );
405- FD_TEST ( cap_execrp_out -> fseq );
406- break ;
407- }
388+ ulong tile_idx = tile -> kind_id ;
389+ ulong idx = fd_topo_find_tile_out_link ( topo , tile , "cap_execrp" , tile_idx );
390+ FD_TEST ( idx != ULONG_MAX );
391+ fd_topo_link_t * link = & topo -> links [ tile -> out_link_id [ idx ] ];
392+ fd_capture_link_buf_t * cap_execrp_out = ctx -> cap_execrp_out ;
393+ cap_execrp_out -> base .vt = & fd_capture_link_buf_vt ;
394+ cap_execrp_out -> idx = idx ;
395+ cap_execrp_out -> mem = topo -> workspaces [ topo -> objs [ link -> dcache_obj_id ].wksp_id ].wksp ;
396+ cap_execrp_out -> chunk0 = fd_dcache_compact_chunk0 ( cap_execrp_out -> mem , link -> dcache );
397+ cap_execrp_out -> wmark = fd_dcache_compact_wmark ( cap_execrp_out -> mem , link -> dcache , link -> mtu );
398+ cap_execrp_out -> chunk = cap_execrp_out -> chunk0 ;
399+ cap_execrp_out -> mcache = link -> mcache ;
400+ cap_execrp_out -> depth = fd_mcache_depth ( link -> mcache );
401+ cap_execrp_out -> seq = 0UL ;
402+
403+ ulong consumer_tile_idx = fd_topo_find_tile (topo , "solcap" , 0UL );
404+ fd_topo_tile_t * consumer_tile = & topo -> tiles [ consumer_tile_idx ];
405+ cap_execrp_out -> fseq = NULL ;
406+ for ( ulong j = 0UL ; j < consumer_tile -> in_cnt ; j ++ ) {
407+ if ( FD_UNLIKELY ( consumer_tile -> in_link_id [ j ] == link -> id ) ) {
408+ cap_execrp_out -> fseq = fd_fseq_join ( fd_topo_obj_laddr ( topo , consumer_tile -> in_link_fseq_obj_id [ j ] ) );
409+ FD_TEST ( cap_execrp_out -> fseq );
410+ break ;
408411 }
409-
410- ctx -> capture_ctx -> capture_solcap = 1 ;
411- ctx -> capture_ctx -> capctx_type .buf = cap_execrp_out ;
412- ctx -> capture_ctx -> capture_link = & cap_execrp_out -> base ;
413412 }
414413
415- if ( strlen ( tile -> execrp .dump_proto_dir ) ) {
416- ctx -> capture_ctx -> dump_proto_output_dir = tile -> execrp .dump_proto_dir ;
417- ctx -> capture_ctx -> dump_proto_start_slot = tile -> execrp .capture_start_slot ;
418- ctx -> capture_ctx -> dump_syscall_name_filter = tile -> execrp .dump_syscall_name_filter ;
419- ctx -> capture_ctx -> dump_instr_to_pb = tile -> execrp .dump_instr_to_pb ;
420- ctx -> capture_ctx -> dump_txn_to_pb = tile -> execrp .dump_txn_to_pb ;
421- ctx -> capture_ctx -> dump_syscall_to_pb = tile -> execrp .dump_syscall_to_pb ;
422- ctx -> capture_ctx -> dump_elf_to_pb = tile -> execrp .dump_elf_to_pb ;
423- }
414+ ctx -> capture_ctx -> capture_solcap = 1 ;
415+ ctx -> capture_ctx -> capctx_type .buf = cap_execrp_out ;
416+ ctx -> capture_ctx -> capture_link = & cap_execrp_out -> base ;
417+ }
418+
419+ ctx -> dump_proto_ctx = NULL ;
420+ if ( FD_UNLIKELY ( strlen ( tile -> execrp .dump_proto_dir ) ) ) {
421+ ctx -> dump_proto_ctx = dump_proto_ctx_mem ;
422+ ctx -> dump_proto_ctx -> dump_proto_output_dir = tile -> execrp .dump_proto_dir ;
423+ ctx -> dump_proto_ctx -> dump_proto_start_slot = tile -> execrp .capture_start_slot ;
424+ ctx -> dump_proto_ctx -> dump_syscall_name_filter = tile -> execrp .dump_syscall_name_filter ;
425+ ctx -> dump_proto_ctx -> dump_instr_to_pb = !!tile -> execrp .dump_instr_to_pb ;
426+ ctx -> dump_proto_ctx -> dump_txn_to_pb = !!tile -> execrp .dump_txn_to_pb ;
427+ ctx -> dump_proto_ctx -> dump_syscall_to_pb = !!tile -> execrp .dump_syscall_to_pb ;
428+ ctx -> dump_proto_ctx -> dump_elf_to_pb = !!tile -> execrp .dump_elf_to_pb ;
424429 }
425430
426431 /********************************************************************/
@@ -437,6 +442,7 @@ unprivileged_init( fd_topo_t * topo,
437442 ctx -> runtime -> log .enable_vm_tracing = 0 ;
438443 ctx -> runtime -> log .tracing_mem = & ctx -> tracing_mem [0 ][0 ];
439444 ctx -> runtime -> log .capture_ctx = ctx -> capture_ctx ;
445+ ctx -> runtime -> log .dump_proto_ctx = ctx -> dump_proto_ctx ;
440446
441447 memset ( & ctx -> metrics , 0 , sizeof (ctx -> metrics ) );
442448 memset ( & ctx -> runtime -> metrics , 0 , sizeof (ctx -> runtime -> metrics ) );
0 commit comments