Skip to content

[XDebug Bridge] Fetch all array keys when inspecting an array #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: trunk
Choose a base branch
from

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Jul 23, 2025

Motivation for the change, related issues

Fixes two problems:

  • Fetches all the array keys when inspecting arrays. property_get XDebug command is paginated and before this PR, we'd only see a subset of all the array keys. With this PR, we see all the keys. This will be a problem on huge arrays so we'll need to bucket keys into group of 1000 in a follow-up PR.
  • Supports actually browsing superglobals, e.g. $_SERVER. Before this PR, you'd only see another nested superglobal (see the screenshot below).

As for the latter, I'm not too happy about the solution – we're reaching for the nested XDebug .property.property when it's available. I expect that will lead us astray in some scenarios, e.g. when browsing arrays that have nested arrays. That being said, I couldn't easily break it so let's get it in and continue iterating:

const responseProps =
	response.property?.property ?? response.property;

Testing instructions

Run nx run php-wasm-cli:dev --xdebug --devtools xdebug.php before and after this PR. Confirm you see the following results:

Before

CleanShot 2025-07-24 at 00 33 54@2x

After ($_SERVER is still duplicated – let's fix that separately)

CleanShot 2025-07-24 at 00 32 50@2x

Base automatically changed from add-cdp-option-in-cli to trunk July 24, 2025 08:10
@mho22 mho22 mentioned this pull request Jul 24, 2025
10 tasks
@mho22
Copy link
Collaborator

mho22 commented Jul 28, 2025

I think I found a way to avoid having that duplicate array inside itself. When paginating, the last element is the ement itself with :

{
  '$': {
    name: '$_ENV',
    fullname: '$_ENV',
    type: 'array',
    children: '1',
    numchildren: '86',
    page: '3',
    pagesize: '32'
  }
}

So instead of injecting the object itself again in the array, let's check if the current page is actually '0' and add it. Do nothing otherwise.

xdebug-cdp-bridge.ts on line 795

	// Use same depth/context as parent
	this.objectHandles.set(childObjectId, {
		type: 'property',
		depth: depth,
		contextId: contextId,
		fullname: prop.$.fullname || name,
	});

+	if (prop.$.page == 0) {
		currentProps.push({
			name: prop.$.key || name,
			value: {
				type: 'object',
				className: className,
				description: className,
				objectId: childObjectId,
			},
			writable: false,
			configurable: false,
			enumerable: true,
		});
+	}
} else { 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants