From 0ce7d86d6a53b38ed75045173da33b277415254d Mon Sep 17 00:00:00 2001 From: Tamas Koczka Date: Wed, 28 Jan 2026 14:34:43 +0000 Subject: pkg/codesearch: expose struct layout in codesearch - Extract struct field offsets and sizes in the C++ codesearch indexer. - Add 'fields' to the JSON definition output. - Update pkg/codesearch to parse and expose the new field information. - Add 'struct-layout' command to syz-codesearch for debugging. - Add 'codesearch-struct-layout' tool to pkg/aflow/tool/codesearcher/ to allow LLM agents to query struct memory layout and map byte offsets to fields. - Support pointer marshaling for optional JSON values (e.g. *uint) --- pkg/codesearch/testdata/source0.c.json | 70 +++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'pkg/codesearch/testdata/source0.c.json') diff --git a/pkg/codesearch/testdata/source0.c.json b/pkg/codesearch/testdata/source0.c.json index 451ab58cc..39e4b6775 100644 --- a/pkg/codesearch/testdata/source0.c.json +++ b/pkg/codesearch/testdata/source0.c.json @@ -192,7 +192,14 @@ "start_line": 36, "end_line": 38 }, - "comment": {} + "comment": {}, + "fields": [ + { + "name": "x", + "offset": 0, + "size": 32 + } + ] }, { "name": "some_struct", @@ -202,7 +209,19 @@ "start_line": 17, "end_line": 20 }, - "comment": {} + "comment": {}, + "fields": [ + { + "name": "x", + "offset": 0, + "size": 32 + }, + { + "name": "y", + "offset": 32, + "size": 32 + } + ] }, { "name": "some_struct_with_a_comment", @@ -216,7 +235,19 @@ "file": "source0.h", "start_line": 24, "end_line": 26 - } + }, + "fields": [ + { + "name": "x", + "offset": 0, + "size": 32 + }, + { + "name": "other_struct", + "offset": 64, + "size": 64 + } + ] }, { "name": "struct_in_c_file", @@ -226,7 +257,19 @@ "start_line": 6, "end_line": 9 }, - "comment": {} + "comment": {}, + "fields": [ + { + "name": "X", + "offset": 0, + "size": 32 + }, + { + "name": "by_value", + "offset": 32, + "size": 64 + } + ] }, { "name": "some_union", @@ -236,7 +279,24 @@ "start_line": 40, "end_line": 44 }, - "comment": {} + "comment": {}, + "fields": [ + { + "name": "x", + "offset": 0, + "size": 32 + }, + { + "name": "p", + "offset": 0, + "size": 64 + }, + { + "name": "s", + "offset": 0, + "size": 64 + } + ] }, { "name": "some_enum", -- cgit mrf-deployment