Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and i'm not very familiar with development/debugging tools. If I have a php script say 20 lines,
How can I see a path of the corresponding C code which is executed? What If i would like to break at a certain php line in the script, is it possible?
Thanks,
Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and i'm not very familiar with development/debugging tools. If I have a php script say 20 lines,
How can I see a path of the corresponding C code which is executed? What If i would like to break at a certain php line in the script, is it possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.
It's also nice to see what PHP is actually doing and a way to learn the
internals of PHP.
2012/2/13 Ángel González keisial@gmail.com
Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and
i'm not very familiar with development/debugging tools. If I have a php
script say 20 lines,
How can I see a path of the corresponding C code which is executed? What
If i would like to break at a certain php line in the script, is it
possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.
I've used etrace: http://ndevilla.free.fr/etrace/ with php recently, works nicely. Produces output like:
main
| Crumble_make_apple_crumble
| | Crumble_buy_stuff
| | | Crumble_buy
| | | Crumble_buy (total: 5 times)
| | Crumble_prepare_apples
| | | Crumble_skin_and_dice
Also, if you want to step-by-step debug I use eclipse CDT on a Linux virtual machine.
-----Original Message-----
From: Yader Hernandez [mailto:yader.hernandez@gmail.com]
Sent: Monday, February 13, 2012 5:24 PM
To: Ángel González
Cc: Adi Mutu; PHP Developers Mailing List
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
It's also nice to see what PHP is actually doing and a way to learn the internals of PHP.
2012/2/13 Ángel González keisial@gmail.com
Hello,
Perhaps this is a stupid question, but i haven't coded in C in years
and
i'm not very familiar with development/debugging tools. If I have a
php script say 20 lines,
How can I see a path of the corresponding C code which is executed?
What
If i would like to break at a certain php line in the script, is it
possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard
way by doing that.--
To unsubscribe,
visit: http://www.php.net/unsub.php
Perhaps i didn't explain correctly, my bad, sorry.
Basically what I want to see is the corresponding C code which is executed, i could put a break in gdb, but how do I know at which C function to put it, if i don't know the internals of php very good?
From: Ángel González keisial@gmail.com
To: Adi Mutu adi_mutu06@yahoo.com
Cc: PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 1:11 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and i'm not very familiar with development/debugging tools. If I have a php script say 20 lines,
How can I see a path of the corresponding C code which is executed? What If i would like to break at a certain php line in the script, is it possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.
2012/2/14 Adi Mutu adi_mutu06@yahoo.com
Perhaps i didn't explain correctly, my bad, sorry.
Basically what I want to see is the corresponding C code which is
executed, i could put a break in gdb, but how do I know at which C function
to put it, if i don't know the internals of php very good?
And the answer is : you cant.
Simply put, you have to study the code first, before knowing through which
line it will go.
That's not very easy, as you can count on ~800.000 lines in trunk.
To see the path, use valgrind + callgrind. You'll get a very cool graph
like this :
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation/images/PHPInternals-callgraph.png
You could use gdb with the .gdbinit from trunk. Using it with CDT is much
more cool as it is GUI.
I wrote some article about PHP internals, mainly describing how it works.
It's in french (
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation)
with some schema.
Mainly, the hardest part is ZendVM. If you dont have to debug ZendVM, it's
kinda "easy" and logic.
Cheers
Julien.Pauli
From: Ángel González keisial@gmail.com
To: Adi Mutu adi_mutu06@yahoo.com
Cc: PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 1:11 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and
i'm not very familiar with development/debugging tools. If I have a php
script say 20 lines,
How can I see a path of the corresponding C code which is executed? What
If i would like to break at a certain php line in the script, is it
possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.
Thanks Julien....
I don't know french, but i'll read it using google translate:)
From: jpauli jpauli@php.net
To: Adi Mutu adi_mutu06@yahoo.com
Cc: Ángel González keisial@gmail.com; PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 11:17 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
2012/2/14 Adi Mutu adi_mutu06@yahoo.com
Perhaps i didn't explain correctly, my bad, sorry.
Basically what I want to see is the corresponding C code which is
executed, i could put a break in gdb, but how do I know at which C function
to put it, if i don't know the internals of php very good?
And the answer is : you cant.
Simply put, you have to study the code first, before knowing through which
line it will go.
That's not very easy, as you can count on ~800.000 lines in trunk.
To see the path, use valgrind + callgrind. You'll get a very cool graph
like this :
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation/images/PHPInternals-callgraph.png
You could use gdb with the .gdbinit from trunk. Using it with CDT is much
more cool as it is GUI.
I wrote some article about PHP internals, mainly describing how it works.
It's in french (
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation)
with some schema.
Mainly, the hardest part is ZendVM. If you dont have to debug ZendVM, it's
kinda "easy" and logic.
Cheers
Julien.Pauli
From: Ángel González keisial@gmail.com
To: Adi Mutu adi_mutu06@yahoo.com
Cc: PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 1:11 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)Hello,
Perhaps this is a stupid question, but i haven't coded in C in years and
i'm not very familiar with development/debugging tools. If I have a php
script say 20 lines,
How can I see a path of the corresponding C code which is executed? What
If i would like to break at a certain php line in the script, is it
possible?Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.
Thanks Julien....
I don't know french, but i'll read it using google translate:)
If you just want to see some of the function calls, most calls that are
visible in userspace are prefixed with "zif_" internally.
eg.
% gdb sapi/cli/php
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
...
(gdb) b zif_strlen
Breakpoint 1 at 0x7b2760: file
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
line 455.
(gdb) run -r 'echo strlen("123");'
Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
at
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
455 {
(gdb) l
450
451
452 /* {{{ proto int strlen(string str)
453 Get string length */
454 ZEND_FUNCTION(strlen)
455 {
456 char *s1;
457 int s1_len;
-Rasmus
Thanks Julien....
I don't know french, but i'll read it using google translate:)
If you just want to see some of the function calls, most calls that are
visible in userspace are prefixed with "zif_" internally.eg.
% gdb sapi/cli/php
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
...
(gdb) b zif_strlen
Breakpoint 1 at 0x7b2760: file
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
line 455.
(gdb) run -r 'echo strlen("123");'
Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
at
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
455 {
(gdb) l
450
451
452 /* {{{ proto int strlen(string str)
453 Get string length */
454 ZEND_FUNCTION(strlen)
455 {
456 char *s1;
457 int s1_len;-Rasmus
--
Yeah, that's the PHP_FUNCTION() macro. 'zif' meaning "Zend Internal
Function".
One more step would be to read the preprocessed code (GCC -E), as PHP
source heavily uses macros
If you want, you can also read the source code online using the excellent
http://lxr.php.net :)
Julien.P
I know about the zif_* functions and i'm already using lxr.php.net.
Didn't know about Gcc -e trick though, that might be usefull.
Thanks.
From: jpauli jpauli@php.net
To: Rasmus Lerdorf rasmus@php.net
Cc: Adi Mutu adi_mutu06@yahoo.com; PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 7:36 PM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
Thanks Julien....
I don't know french, but i'll read it using google translate:)
If you just want to see some of the function calls, most calls that are
visible in userspace are prefixed with "zif_" internally.eg.
% gdb sapi/cli/php
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
...
(gdb) b zif_strlen
Breakpoint 1 at 0x7b2760: file
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
line 455.
(gdb) run -r 'echo strlen("123");'
Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
at
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
455 {
(gdb) l
450
451
452 /* {{{ proto int strlen(string str)
453 Get string length */
454 ZEND_FUNCTION(strlen)
455 {
456 char *s1;
457 int s1_len;-Rasmus
--
Yeah, that's the PHP_FUNCTION() macro. 'zif' meaning "Zend Internal
Function".
One more step would be to read the preprocessed code (GCC -E), as PHP
source heavily uses macros
If you want, you can also read the source code online using the excellent
http://lxr.php.net :)
Julien.P
I know about the zif_* functions and i'm already using lxr.php.net.
Didn't know about gcc -E trick though, that might be usefull.
Thanks.
From: jpauli jpauli@php.net
To: Rasmus Lerdorf rasmus@php.net
Cc: Adi Mutu adi_mutu06@yahoo.com; PHP Developers Mailing List internals@lists.php.net
Sent: Tuesday, February 14, 2012 7:36 PM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
Thanks Julien....
I don't know french, but i'll read it using google translate:)
If you just want to see some of the function calls, most calls that are
visible in userspace are prefixed with "zif_" internally.eg.
% gdb sapi/cli/php
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
...
(gdb) b zif_strlen
Breakpoint 1 at 0x7b2760: file
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
line 455.
(gdb) run -r 'echo strlen("123");'
Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
at
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
455 {
(gdb) l
450
451
452 /* {{{ proto int strlen(string str)
453 Get string length */
454 ZEND_FUNCTION(strlen)
455 {
456 char *s1;
457 int s1_len;-Rasmus
--
Yeah, that's the PHP_FUNCTION() macro. 'zif' meaning "Zend Internal Function".
One more step would be to read the preprocessed code (GCC -E), as PHP source heavily uses macros
If you want, you can also read the source code online using the excellent http://lxr.php.net :)
Julien.P