Skip to content

Commit b55215b

Browse files
committed
Backtraces & 8.1 in dbg preview
1 parent b00348e commit b55215b

File tree

6 files changed

+88
-24
lines changed

6 files changed

+88
-24
lines changed

.gitignore

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
/php*.js
22
/php*.mjs
3-
/php*.js.br
4-
/php*.mjs.br
5-
/php*.js.gz
6-
/php*.mjs.gz
73
/php*.wasm
84
/php*.wat
9-
/php-*.wasm.gz
10-
/php-*.wasm.br
115
/php*.wasm.map
126
/php*.data
13-
/php*.data.gz
14-
/php*.data.br
157
docs-source/app/assets/php*.js
168
docs-source/app/assets/php*.wasm
17-
docs-source/app/assets/php*.wasm.gz
18-
docs-source/app/assets/php*.wasm.br
199
docs-source/app/assets/php*.wat
2010
docs-source/app/assets/php*.wasm.map
2111
docs-source/app/assets/php*.data
22-
docs-source/app/assets/php*.data.gz
23-
docs-source/app/assets/php*.data.br
2412
/Php*.js
2513
/Php*.mjs
2614
/*.js
@@ -61,3 +49,5 @@ demo-web/public/static/media/mapped/*
6149
packages/**/index.html
6250
packages/*.tar.gz
6351
packages/dependencies.json
52+
*.gz
53+
*.br

demo-web/src/Debugger.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export default forwardRef(function Debugger({
113113
const [userClasses, setUserClasses] = useState({});
114114

115115
const [includedFiles, setIncludedFiles] = useState([]);
116+
const [trace, setTrace] = useState([]);
116117

117118
const [currentPanel, setCurrentPanel] = useState('none');
118119

@@ -368,6 +369,10 @@ export default forwardRef(function Debugger({
368369
case 'files':
369370
setIncludedFiles( await (await phpRef.current).dumpFiles() || [] );
370371
break;
372+
373+
case 'trace':
374+
setTrace( await (await phpRef.current).dumpBacktrace() || [] );
375+
break;
371376
}
372377
}
373378
else
@@ -469,6 +474,11 @@ export default forwardRef(function Debugger({
469474
setIncludedFiles( await (await phpRef.current).dumpFiles() || [] );
470475
setCurrentPanel('files');
471476
break;
477+
478+
case 'trace':
479+
setTrace( await (await phpRef.current).dumpBacktrace() || [] );
480+
setCurrentPanel('trace');
481+
break;
472482
}
473483
};
474484

@@ -496,6 +506,7 @@ export default forwardRef(function Debugger({
496506
<button onClick = {async () => switchRightPanel('classes')}>classes</button>
497507
<button onClick = {async () => switchRightPanel('functions')}>functions</button>
498508
<button onClick = {async () => switchRightPanel('files')}>files</button>
509+
<button onClick = {async () => switchRightPanel('trace')}>trace</button>
499510
</div>
500511
<div className='phpdbg-panel-frame inset'>
501512
<div className='phpdbg-panel-frame-inner'>
@@ -529,6 +540,13 @@ export default forwardRef(function Debugger({
529540
</div>
530541
})}
531542
</div>
543+
<div className='phpdbg-panel phpdbg-trace'>
544+
{trace.map((frame) => {
545+
return <div key={frame.frame} onClick = {() => openFile(frame.filename, frame.lineNo)}>
546+
<span>{frame.filename}: {frame.lineNo}</span>
547+
</div>
548+
})}
549+
</div>
532550
</div>
533551
</div>
534552
</div>

demo-web/src/Editor.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@
139139

140140
.editor iframe {
141141
flex-grow: 1;
142+
}
143+
144+
select.bevel option {
145+
background-color: #FFF;
142146
}

demo-web/src/Editor.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ export default function Editor() {
176176
window.history.replaceState({}, null, window.location.pathname + '?' + query);
177177
}
178178

179+
if(currentPath.current !== path)
180+
{
181+
activeLines.current.forEach(m => {
182+
editor.session.removeMarker(m);
183+
activeLines.current.delete(m);
184+
});
185+
}
186+
179187
currentPath.current = path;
180188

181189
editor.setReadOnly(!!openDbg.current);
@@ -309,11 +317,6 @@ export default function Editor() {
309317

310318
if(exists)
311319
{
312-
activeLines.current.forEach(m => {
313-
editor.session.removeMarker(m);
314-
activeLines.current.delete(m);
315-
});
316-
317320
await openFile(file);
318321

319322
editor.scrollToLine(-1 + line, true, true, () => {});
@@ -361,11 +364,6 @@ export default function Editor() {
361364

362365
if(exists)
363366
{
364-
activeLines.current.forEach(m => {
365-
editor.session.removeMarker(m);
366-
activeLines.current.delete(m);
367-
});
368-
369367
await openFile(file);
370368

371369
activeLines.current.forEach(m => {
@@ -425,10 +423,11 @@ export default function Editor() {
425423
</button>
426424
{!isExecuting ? (
427425
<>
428-
{phpdbg ? '' : <select defaultValue = '8.3' ref={versionSelector}>
426+
{phpdbg ? '' : <select className='bevel' defaultValue = '8.3' ref={versionSelector}>
429427
<option>8.4</option>
430428
<option>8.3</option>
431429
<option>8.2</option>
430+
<option>8.1</option>
432431
</select>}
433432
<button className='square' title = "Debugger" onClick = {handleStartDebugger}>
434433
{phpdbg ? '⏹' : '▶'}

demo-web/src/dbg-preview.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@
257257
display: initial;
258258
}
259259

260+
[data-current-panel="trace"] .phpdbg-panel.phpdbg-trace {
261+
display: initial;
262+
}
263+
260264

261265
.phpdbg-panel-frame {
262266
position: relative;
@@ -276,6 +280,7 @@
276280

277281
.phpdbg-panel.phpdbg-files > div,
278282
.phpdbg-panel.phpdbg-classes > div,
283+
.phpdbg-panel.phpdbg-trace > div,
279284
.phpdbg-panel.phpdbg-functions > div {
280285
padding: 0.5rem;
281286
border-bottom: 1px solid #CCC;
@@ -284,6 +289,7 @@
284289

285290
.phpdbg-panel.phpdbg-files > div span,
286291
.phpdbg-panel.phpdbg-classes > div span,
292+
.phpdbg-panel.phpdbg-trace > div,
287293
.phpdbg-panel.phpdbg-functions > div > span {
288294
cursor: pointer;
289295
}

source/PhpDbgWeb.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class PhpDbgWeb extends PhpBase
6565
{
6666
const php = (await this.binary);
6767

68-
const cmd = ['phpdbg', '-c', '/php.ini', '-e'];
68+
const cmd = ['phpdbg', '-c', '/php.ini', '-e'];
6969

7070
const ptrs = cmd.map(part => {
7171
const len = php.lengthBytesUTF8(part) + 1;
@@ -372,6 +372,53 @@ export class PhpDbgWeb extends PhpBase
372372
return files;
373373
}
374374

375+
async dumpBacktrace()
376+
{
377+
const php = await this.binary;
378+
379+
const ptr = php.ccall(
380+
'vrzno_dbg_dump_backtrace'
381+
, NUM
382+
, []
383+
, []
384+
, {}
385+
);
386+
387+
console.log({ptr});
388+
389+
const heap = new DataView(php.HEAP8.buffer);
390+
const end = ptr + heap.getInt32(ptr, true);
391+
const pointerLen = 4;
392+
393+
let cur = ptr + pointerLen;
394+
const dec = new TextDecoder;
395+
const frames = [];
396+
397+
let i = 0;
398+
399+
while(cur < end)
400+
{
401+
const filenameLen = heap.getInt32(cur, true);
402+
cur += pointerLen;
403+
404+
const filename = dec.decode(php.HEAP8.slice(cur, cur + filenameLen));
405+
cur += filenameLen + 1;
406+
407+
const lineNo = heap.getInt32(cur, true);
408+
cur += pointerLen;
409+
410+
frames.push({filename, lineNo, frame: i});
411+
412+
i++;
413+
}
414+
415+
console.log(frames);
416+
417+
php._free(ptr);
418+
419+
return frames;
420+
}
421+
375422
async refresh()
376423
{
377424
// super.refresh();

0 commit comments

Comments
 (0)