com php-src: add intro tutorial: tutorials/intro.md
| From: | Bob Weinand | Date: | Wed, 13 Nov 2013 09:55:06 +0000 |
| Subject: | com php-src: add intro tutorial: tutorials/intro.md | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-75018@lists.php.net to get a copy of this message | ||
Commit: 0f2c75efb28328a9092007670294db7d1dfe8940
Author: krakjoe <joe.watkins@live.co.uk> Wed, 13 Nov 2013 09:55:06 +0000
Parents: 216c1f5e993362456e6cda2a186c0f1bcb5ecf19
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0f2c75efb28328a9092007670294db7d1dfe8940
Log:
add intro tutorial
Changed paths:
A tutorials/intro.md
Diff:
diff --git a/tutorials/intro.md b/tutorials/intro.md
new file mode 100644
index 0000000..fa1c99e
--- /dev/null
+++ b/tutorials/intro.md
@@ -0,0 +1,103 @@
+Getting Started with phpdbg
+===========================
+*An introduction to debugging PHP code with phpdbg*
+
+phpdbg provides an interactive environment to debug PHP; it id implemented and distributed as a
SAPI module - just as the CLI interface.
+
+
+
+phpdbg integrates with, and initializes the Zend environment; from the moment the console is open
you can start to manipulate the environment in order to prepare your debugging session. phpdbg may
feel familiar to other debuggers, but now is a good time to ask for help:
+
+
+
+phpdbg provides detailed help for all of the supported commands (that are not really obvious).
+
+Breaking Execution
+==================
+*Telling phpdbg when to stop ...*
+
+In order to debug your code, execution must be interrupted at a very specific points during
execution, and allow access to, and inspection of, the execution environment. For extreeme
circumstances, and geeks (me included), phpdbg can step through the execution of your script,
showing you information about every opcode the vm executes, including the address (in case you need
to break at that specific point on the next execution).
+
+phpdbg provides many options for specifying break points, as illustrated by a screenshot of the
help menu for the break command:
+
+
+
+In those case where you wish to program your break points in userland, phpdbg includes a userland
API, in the shape of two simple functions:
+
+```
+/**
+* Sets a breakpoint at the next opcode address
+* @return void
+*/
+proto void phpdbg_break(void);
+```
+
+
+```
+/**
+* Clear breakpoints before continuing execution
+* @return void
+*/
+proto void phpdbg_clear(void);
+```
+
+Inspecting the Environment
+==========================
+*Finding out what went wrong*
+
+When a breakpoint is reached, control is passed back to the phpdbg console (you!), execution will
not continue until the *next* command is issued, a breakpoint being reached looks something like:
+
+
+
+Now is the time to get down to some serious evil(), er, I mean eval()
+
+Direct access to eval allows you to change _anything_ at _any_ time during execution. Helpful
printing and listing commands help you to make sense of addresses and remind you of the names of the
variables you want to var_dump !!
+
+Library code for this section:
+
+```
+<?php
+class phpdbg {
+ public function isGreat($greeting = null) {
+ printf(
+ "%s: %s\n", __METHOD__, $greeting);
+ return $this;
+ }
+}
+
+$dbg = new phpdbg();
+
+var_dump(
+ $dbg->isGreat("PHP Rocks !!"));
+?>
+```
+
+Being Precise
+=============
+*Don't be sloppy, ever ... true story*
+
+Actually the ability to break at function entry, or even on a single statement, is not always exact
enough. A single statement may be many opcodes, and it could be any of those instructions that are
ruining your day. So, phpdbg allows you to specify an exact opcode address, and provides the ability
to view the instructions of any method or function before execution occurs.
+
+Looking up addresses is made easy by the *print* command
+
+
+
+For simple scripts, like the library code in the last section, and times when you want as much
verboseness as possibe, the following might be an option:
+
+
+
+Mocking a Server
+================
+*One sentence, seriously!*
+
+Mocking a specific environment is childs play, simply include a bootstrap file before you run, or
have your code include it, an example of such a file can be found in the repository:
+
+https://github.com/krakjoe/phpdbg/blob/master/web-bootstrap.php
+
+Advice You Can Keep !!
+======================
+*The reason for all the images ...*
+
+The best thing about this tutorial is you take all the help with you when you install phpdbg ...
don't be afraid to ask for help :)
+
+Happy phping :)