Skip to content

Commit b387e17

Browse files
committed
feat: user defined custom list types
1 parent 23f14a3 commit b387e17

7 files changed

+333
-161
lines changed

README.md

+39-22
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ variables.
2323

2424
### Show contents of containers
2525

26-
Extension support showing contents of containers: `List` (including subtypes)
27-
and `Bitmapset`.
26+
Extension support showing contents of containers: `List` (including Oid, TransactionId, int and custom user pointer types) and `Bitmapset`.
2827

2928
![List * expansion](resources/list.gif)
3029

@@ -35,13 +34,11 @@ and `Bitmapset`.
3534

3635
![Bitmapset expansion](resources/bitmapset.gif)
3736

38-
Also, there is support for C-arrays (like `PlannerInfo->simple_rel_array`) -
39-
array is displayed using it's length.
37+
Also, there is support for C-arrays (like `PlannerInfo->simple_rel_array`) - array is displayed using it's length.
4038

4139
![Planner expansion](resources/planner.gif)
4240

43-
Currently, there are 36 registered array members, but you can add your own
44-
using [pgsql_hacker_helper.json](#pgsql_hacker_helperjson) configuration file.
41+
Currently, there are 36 registered array members, but you can add your own using [pgsql_hacker_helper.json](#pgsql_hacker_helperjson) configuration file.
4542

4643
### Show where Bitmapset references
4744

@@ -134,7 +131,7 @@ Example json:
134131

135132
```json
136133
{
137-
"version": 3,
134+
"version": 4,
138135
"specialMembers": {
139136
"array": [
140137
{
@@ -160,13 +157,30 @@ Example json:
160157
"type": "PlannerInfo *"
161158
}
162159
],
163-
"typedefs": "my.typedefs.file"
160+
"typedefs": "my.typedefs.file",
161+
"customListTypes": [
162+
{
163+
"type": "char *",
164+
"member": ["UserData", "knownNames"]
165+
},
166+
{
167+
"type": "struct FileChunks *",
168+
"variable": ["ProcessFileChunks", "chunks"]
169+
}
170+
]
164171
}
165172
```
166173

167-
In example 3 array special members - arrays will be shown with specified length,
168-
not just pointers to arrays start.
169-
Also, `PlannerRef` - typedef for `PlannerInfo *`.
174+
Features:
175+
176+
- 3 *array* special members (pointer field used as array) - `"typeName"->"memberName"` will be shown with length `"typeName"->"lengthExpression"`, not as simple pointers.
177+
178+
- `PlannerRef` - custom user typedef for `PlannerInfo *`.
179+
180+
- `UserData->knownNames` is a `List *` that contains pointer elements not `Node *`, but `char *` (`List` of strings).
181+
Variable `chunks` in function `ProcessFileChunks` is a `List` that contains pointer elements not `Node *`, but `struct FileChunks *`.
182+
183+
- User provided custom `typedefs` list (used by formatter).
170184

171185
For more info check [configuration file documentation](./docs/config_file.md).
172186

@@ -218,30 +232,34 @@ Minimal supported version of:
218232
> It is tested manually and not all use cases might be covered. If you found
219233
> bug specific to some version please [create issue](https://github.com/ashenBlade/postgres-dev-helper/issues).
220234
221-
Also, extension will target latest VS Code version and try to use the full
222-
functionality of new versions. So, use latest VS Code versions to get new
223-
features earlier.
235+
Also, extension will target latest VS Code version and try to use the full functionality of new versions.
236+
So, use latest VS Code versions to get new features earlier.
224237

225238
For using formatter minimal supported version Postgres is `10`.
226239

240+
> WARN: I *do not stand* that all extension features will work as expected on all versions
241+
227242
## Known Issues
228243

229244
Known issues:
230245

231-
- If in pointer variable was garbage, extension will not detect it and expand
232-
this variable (may be garbage).
246+
- If in pointer variable was garbage, extension will not detect it and expand this variable (may be garbage).
247+
Usually, this will not lead to fatal errors, just note this.
233248
- To get NodeTags extension reads all available NodeTag files (from settings),
234249
but these files may be not created (./configure or make not run). I assume by
235-
time of debugging start files will be created, so extension catch them and
236-
process.
237-
- Tested only with [ms-vscode.cpptools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
238-
extension. Currently, no support for other DAP adapters (i.e. Code LLDB)
250+
time of debugging start files will be created, so extension catch them and process.
251+
- Works only with [ms-vscode.cpptools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
252+
extension. Currently, no support for other DAP adapters (i.e. Code LLDB).
253+
Reason: strongly tied to output format of this extension (not only expression evaluation, but stack trace format i.e.)
239254
- Sometimes formatting can misbehave. This is due to `pg_bsd_indent` internal
240255
logic. If formatting is not applied try run command again. If file after
241256
formatting is a mess this can be due to errors in logic.
242257
- Some operations require data to be allocated (usually, for function invocation).
243258
For this, `palloc` and `pfree` are used. So if you are debugging memory subsystem
244259
you may want to disable extension, because it may affect debugging process.
260+
- Some operations require for some work to be done with system catalog.
261+
For example, to get function name using it's Oid. So, system catalog (system cache)
262+
can be modified during extension work.
245263

246264
## Release Notes
247265

@@ -386,5 +404,4 @@ Call `pprint(Node *)` on selected variable in `Variables` view.
386404

387405
## Contributing
388406

389-
Go to [Issues](https://github.com/ashenBlade/postgres-dev-helper/issues) if you
390-
want to say something: bugs, features, etc...
407+
Go to [Issues](https://github.com/ashenBlade/postgres-dev-helper/issues) if you want to say something: bugs, features, etc...

dev/release-checklist.md

-62
This file was deleted.

docs/config_file.md

+51-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ It stored inside `.vscode` folder.
55

66
## Layout
77

8-
There are 2 versions of config file layout.
9-
Version is specified using top level `"version"` field.
8+
There are 4 versions of config file layout.
9+
Version is specified using `"version"` field.
1010

11-
Current version - 3.
11+
Current version - 4.
1212

1313
> This file belongs to latest schema version.
1414
@@ -156,11 +156,58 @@ Read typedefs file `custom.typedefs.list` in current src path.
156156
}
157157
```
158158

159-
Read global typedefs file stored in temporary directory
159+
Read global typedefs file stored in temporary directory.
160160

161161
```json
162162
{
163163
"version": 3,
164164
"typedefs": "/tmp/cached.custom.typedefs.list"
165165
}
166166
```
167+
168+
### Custom `List` types
169+
170+
Usually, `List *` contains nodes (inherits from `Node`), but actually it can contain any pointer.
171+
Extension treats all `List` as they contain `Node` variables, but you can say that this variable or struct member contains custom type (pointer to it).
172+
173+
This information stored in `customListTypes` member. This is array of objects:
174+
175+
```json
176+
{
177+
"version": 4,
178+
"customListTypes": [
179+
{
180+
"type": "MyCustomType *",
181+
"member": ["ParentStruct", "parent_member"]
182+
},
183+
{
184+
"type": "MyCustomType *",
185+
"variable": ["ParentFunction", "variable_name"]
186+
}
187+
]
188+
}
189+
```
190+
191+
Each object contain:
192+
193+
- `type` - fully-qualified type name (that is `struct` or `pointer` should be included) to which pointer will be casted.
194+
- `member` - pair of struct name and member of this struct. Definition looks like this:
195+
196+
```c
197+
typedef struct ParentStruct
198+
{
199+
List *parent_member;
200+
} ParentStruct;
201+
```
202+
203+
- `variable` - pair of function name and variable inside it. Definition looks like this:
204+
205+
```c
206+
void
207+
ParentFunction()
208+
{
209+
List *variable_name;
210+
}
211+
```
212+
213+
With this 2 strategies extension detects `List`s with custom types.

docs/pg_variables.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Also, there are some Special Node types:
9292
- `IntList`
9393
- `OidList`
9494
- `XidList`
95+
96+
Additionally, you can specify custom pointer type in `List`. See [custom `List` types](./config_file.md#custom-list-types) section in configuration file documentation.
9597

9698
- Bitmapset - show elements of set in pseudo-member `$elements$`
9799

@@ -200,9 +202,8 @@ this you should update config file like this:
200202
}
201203
```
202204

203-
There are about 36 supported asm. For example, `simple_rel_array` for `PlannerInfo`
205+
There are about 36 supported ASM. For example, `simple_rel_array` for `PlannerInfo`
204206

205207
![PlannerInfo->simple_rel_array](../resources/tutorial_array_sm.png)
206208

207209
> For more info about configuration check [documentation](config_file.md)
208-

properties.schema.json

+64-2
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,40 @@
8484
},
8585
"version": {
8686
"type": "integer",
87-
"default": 3,
87+
"default": 4,
8888
"enum": [
8989
1,
9090
2,
91-
3
91+
3,
92+
4
9293
],
9394
"description": "Version of configuration file layout. Managed by extension"
95+
},
96+
"customListType": {
97+
"type": "object",
98+
"description": "Description of custom pointer type for specified List",
99+
"properties": {
100+
"type": {
101+
"type": "string",
102+
"pattern": "\\*$",
103+
"description": "Type to which 'ListCell's will be casted"
104+
},
105+
"member": {
106+
"type": "array",
107+
"minItems": 2,
108+
"maxItems": 2,
109+
"description": "Pair of parent struct name and member name inside this struct, identifying this List*"
110+
},
111+
"variable": {
112+
"type": "array",
113+
"minItems": 2,
114+
"maxItems": 2,
115+
"description": "Pair of function name and variable name inside this function, identifying this List*"
116+
}
117+
},
118+
"required": [
119+
"type"
120+
]
94121
}
95122
},
96123
"oneOf": [
@@ -168,6 +195,41 @@
168195
"$ref": "#/definitions/typedefs"
169196
}
170197
}
198+
},
199+
{
200+
"type": "object",
201+
"properties": {
202+
"version": {
203+
"const": 4,
204+
"$ref": "#/definitions/version"
205+
},
206+
"specialMembers": {
207+
"type": "object",
208+
"description": "Configurations for special members",
209+
"properties": {
210+
"array": {
211+
"type": "array",
212+
"description": "Special members that represent arrays - separate fields for array and it's length",
213+
"items": {
214+
"$ref": "#/definitions/arraySpecialMemberV2"
215+
}
216+
}
217+
}
218+
},
219+
"aliases": {
220+
"$ref": "#/definitions/aliasesV2"
221+
},
222+
"typedefs": {
223+
"$ref": "#/definitions/typedefs"
224+
},
225+
"customListTypes": {
226+
"type": "array",
227+
"description": "Array of definitions of custom List types",
228+
"items": {
229+
"$ref": "#/definitions/customListType"
230+
}
231+
}
232+
}
171233
}
172234
],
173235
"required": [

src/constants.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,15 @@ export function getDisplayedExprs(): string[] {
622622
}
623623

624624
export function getKnownCustomListPtrs(): ListPtrSpecialMemberInfo[] {
625-
const member = (type: string, struct: string, member: string): ListPtrSpecialMemberInfo => {
626-
return {
627-
type: type + ' *',
628-
member: [struct, member]
629-
}
630-
}
631-
const variable = (type: string, func: string, variable: string): ListPtrSpecialMemberInfo => {
632-
return {
633-
type: type + ' *',
634-
variable: [func, variable]
635-
}
636-
}
625+
const member = (type: string, struct: string, member: string): ListPtrSpecialMemberInfo => ({
626+
type: type + ' *',
627+
member: [struct, member]
628+
});
629+
630+
const variable = (type: string, func: string, variable: string): ListPtrSpecialMemberInfo => ({
631+
type: type + ' *',
632+
variable: [func, variable]
633+
});
637634

638635
return [
639636
/* contrib/amcheck/verify_heapam.c */

0 commit comments

Comments
 (0)