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) --- .../testdata/query-struct-layout-some-struct | 5 ++ .../query-struct-layout-some-struct-offset | 4 ++ .../testdata/query-struct-layout-some-union | 6 ++ pkg/codesearch/testdata/source0.c.json | 70 ++++++++++++++++++++-- 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 pkg/codesearch/testdata/query-struct-layout-some-struct create mode 100644 pkg/codesearch/testdata/query-struct-layout-some-struct-offset create mode 100644 pkg/codesearch/testdata/query-struct-layout-some-union (limited to 'pkg/codesearch/testdata') diff --git a/pkg/codesearch/testdata/query-struct-layout-some-struct b/pkg/codesearch/testdata/query-struct-layout-some-struct new file mode 100644 index 000000000..a7d8e418e --- /dev/null +++ b/pkg/codesearch/testdata/query-struct-layout-some-struct @@ -0,0 +1,5 @@ +struct-layout testdata/source0.h some_struct + +struct some_struct has 2 fields: +[0 - 32] x +[32 - 64] y diff --git a/pkg/codesearch/testdata/query-struct-layout-some-struct-offset b/pkg/codesearch/testdata/query-struct-layout-some-struct-offset new file mode 100644 index 000000000..8aa337e87 --- /dev/null +++ b/pkg/codesearch/testdata/query-struct-layout-some-struct-offset @@ -0,0 +1,4 @@ +struct-layout testdata/source0.h some_struct 0 + +struct some_struct has 1 fields: +[0 - 32] x diff --git a/pkg/codesearch/testdata/query-struct-layout-some-union b/pkg/codesearch/testdata/query-struct-layout-some-union new file mode 100644 index 000000000..a5891ae6b --- /dev/null +++ b/pkg/codesearch/testdata/query-struct-layout-some-union @@ -0,0 +1,6 @@ +struct-layout testdata/source0.h some_union + +struct some_union has 3 fields: +[0 - 32] x +[0 - 64] p +[0 - 64] s 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