Skip to content

GDB: Python Exception <class 'TypeError'>: exceptions must derive from BaseException #15923

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

Closed
DanielEScherzer opened this issue Sep 16, 2024 · 8 comments

Comments

@DanielEScherzer
Copy link
Member

DanielEScherzer commented Sep 16, 2024

Description

The following code:

<?php

$a = 1;
var_dump( $a );

in /var/www/html/test.php. when run with GDB:

(gdb) set print pretty on
(gdb) break /usr/src/php/ext/standard/var.c:105
Breakpoint 1 at 0x4b6130: file /usr/src/php/ext/standard/var.c, line 105.
(gdb) run /var/www/html/test.php
Starting program: /usr/local/bin/php /var/www/html/test.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, php_var_dump (struc=0x7ffff54140f0, level=1) at /usr/src/php/ext/standard/var.c:113
113             if (level > 1) {
(gdb) p *struc

Where var.c:113 at the time was

if (level > 1) {

Resulted in this output:

$1 = Python Exception <class 'TypeError'>: exceptions must derive from BaseException
Python Exception <class 'TypeError'>: exceptions must derive from BaseException
{
  value = {
    lval = 1,
...
}

But I expected this output instead:

No errors

PHP Version

PHP 8.4-dev

@cmb69
Copy link
Member

cmb69 commented Sep 16, 2024

While I don't understand why PHP would throw a TypeError here, the error message is certainly not related to nice elephpants, but rather to nasty reptiles. ;)

@DanielEScherzer
Copy link
Member Author

While I don't understand why PHP would throw a TypeError here, the error message is certainly not related to nice elephpants, but rather to nasty reptiles. ;)

Its not a PHP type error, its a Python one - I boiled it down to a minimal reproduction case, but I was getting a lot of these (I just started using GDB for PHP)

I see this is tagged as needing feedback - what more can I provide?

@cmb69
Copy link
Member

cmb69 commented Sep 16, 2024

The question is: why do you get a Python error when running/debugging PHP code? I think there is something wrong with your setup.

@DanielEScherzer
Copy link
Member Author

The question is: why do you get a Python error when running/debugging PHP code? I think there is something wrong with your setup.

I believe it is because the GDB stuff is written in python, see https://github.com/php/php-src/blob/1ce07b0957c9323e93c45d0a83c0133aa177a911/scripts/gdb/php_gdb.py

@nielsdos
Copy link
Member

The error likely comes from this line:

raise "Could not find zend_types.h: symbol zend_gc_refcount not found"

You can't raise a string.
@DanielEScherzer Are you using a release build? That could explain why it can't find the symbol required.

@DanielEScherzer
Copy link
Member Author

The error likely comes from this line:

raise "Could not find zend_types.h: symbol zend_gc_refcount not found"

You can't raise a string.
@DanielEScherzer Are you using a release build? That could explain why it can't find the symbol required.

I didn't think I was, but running ./configure --enable-debug and then re-make-ing and trying again fixed the issue. I guess then the attempted error makes sense, but the actual error (from raising a string) is problematic and should still be fixed

@nielsdos
Copy link
Member

Yeah, I'll fix it. Looks like it's just on the master branch.

nielsdos added a commit to nielsdos/php-src that referenced this issue Sep 16, 2024
…s must derive from BaseException

Triggers on release builds when printing data structures.
You can't raise a string, you must raise exceptions.
@cmb69
Copy link
Member

cmb69 commented Sep 16, 2024

I believe it is because the GDB stuff is written in python, see https://github.com/php/php-src/blob/1ce07b0957c9323e93c45d0a83c0133aa177a911/scripts/gdb/php_gdb.py

Ah, I hadn't noticed this yet.

nielsdos added a commit to nielsdos/php-src that referenced this issue Sep 16, 2024
…s must derive from BaseException

Triggers on release builds when printing data structures.
You can't raise a string, you must raise exceptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants