This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 198445 - PHP debug - add ability to stop debugging current page
Summary: PHP debug - add ability to stop debugging current page
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Debugger (show other bugs)
Version: 7.0.1
Hardware: PC Windows XP
: P2 normal with 3 votes (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-09 10:07 UTC by monk.e.boy
Modified: 2013-01-21 15:23 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
ss (72.19 KB, image/bmp)
2011-07-29 13:40 UTC, monk.e.boy
Details
another screen shot (14.86 KB, image/png)
2012-02-06 11:03 UTC, monk.e.boy
Details
Notepad++ dbgp plugin console (7.74 KB, image/png)
2012-02-06 17:03 UTC, miked_187
Details

Note You need to log in before you can comment on or make changes to this bug.
Description monk.e.boy 2011-05-09 10:07:41 UTC
Setup: PHP Xdebug, set netbeans to listen mode. Use Xdebug plugin in Chrome to initiate the debug session. Netbeans project set to stop at first breakpoint.

Problem: While debugging I see the error. I want to stop the debugger, but the only stop button stops the "Listen For Connection". The "Play" button will continue running the current page (which is an issue with database updates as I know they will be wrong).

Solution: Add a "stop running this request" button, but keep the XDebug listener running.
Comment 1 Petr Pisl 2011-05-19 09:09:48 UTC
Do yoy mean by this:

>Netbeans project set to stop at first breakpoint

stop at the first line?

Which error do you see during debugging? 

Anyway it's look like an enhancement.
Comment 2 monk.e.boy 2011-05-19 13:07:00 UTC
> Do yoy mean by this:
> 
> >Netbeans project set to stop at first breakpoint
> 
> stop at the first line?

No, don't stop at the first line. Just stop at a breakpoint.

I had the same issue today. Zend Framework and Doctrine were fighting over handling an exception. Between them were going into an infinite loop and crashing apache.

So I set my breakpoint at the start of the new code and stepped through it.

Then I see the error, so my next task is to stop the execution of PHP because I don't want to crash apache again. How do I do this? I can only press 'Finish Debugger Session' or 'Continue'

I want the third option 'Stop Running Stuff but keep debug session listening'

I saw another IDE had done this with 3 icons. One that looked like a phone that set the IDE into 'listen' mode. Then 'play' and 'stop' for run and stop running.

Thanks for listening, you guys rock, netbeans is getting close to being as usable as my old IDE :)
Comment 3 Ondrej Brejla 2011-07-29 13:06:47 UTC
I'm not sure if I got your point, but you want to have "Pause" button available? For pausing the execution of current script? For this purpose there is a "break" command in dbgp (http://xdebug.org/docs-dbgp.php#break), but it's not supported by xdebug itself (http://bugs.xdebug.org/view.php?id=574). I tried to implement that command in NB, but it really didn't work (unimplemented command in response). So if I really got "your point" as I discribed, I'll close this issue...
Comment 4 monk.e.boy 2011-07-29 13:40:20 UTC
Created attachment 109698 [details]
ss

My problem:

1 set breakpoint
2 run script
3 step through code, see it's going to do the wrong thing e.g. delete a DB table
4 click stop
5 click debug main project
6 refresh page (i.e. go to point 2)

What I want:

1 set breakpoint
2 run script
3 step through code, see it's going to do the wrong thing e.g. delete a DB table
4 click stop
5 refresh page (i.e. go to point 2)

What often happens:

1 set breakpoint
2 run script
3 step through code, see it's going to do the wrong thing e.g. delete a DB table
4 click stop
6 refresh page (debugger is NOT listening due to step 4)
7 page runs and kills my database
8 Sigh. Make a cup of tea. Run my DB build scripts. Wait, then start again at step 1

Part of the problem is that the toolbar shows:

[debug main project arrow] || [stop (finish debug)] [play] [step over] [step in] ... etc

see how the start and stop debug listener are not next to each other. The Finish Debug Listener is next to the Continue button making you think that they are some how related.

I've attached a screen shot to try and show what I mean. Dude, it is hard trying to explain this - lol!!

monk.e.boy
Comment 5 monk.e.boy 2011-07-29 13:42:34 UTC
I want another stop button. One that stops the current script from running, but does nothing to the debug listening connection.
Comment 6 miked_187 2012-02-03 00:54:49 UTC
I filed a similar request in June/10, issue link:  http://netbeans.org/bugzilla/show_bug.cgi?id=187152

Issue was marked as resolved/invalid for some reason, this is basically the same issue here, would be great to see this enhancement implemented
Comment 7 monk.e.boy 2012-02-06 11:03:02 UTC
Created attachment 115489 [details]
another screen shot

another screen shot
Comment 8 miked_187 2012-02-06 17:03:04 UTC
Created attachment 115493 [details]
Notepad++ dbgp plugin console

In Notepad++ they use a square blue box to stop current debugging session while leaving the listener active

They use the round red ball to add a breakpoint on the current line

The properties-like icon is for eval entry 

The Turn OFF button turns off the listener while leaving the debugger pane open, when pressed the button toggles to Turn ON and the listener becomes active

The DBG button opens a non-modal dialog that shows the actual raw commands being sent and received by xdebug (nice to have for debugging xdebug connection/pathing problems)
Comment 9 monk.e.boy 2012-02-06 17:18:48 UTC
Those other icons for step into, step over etc are WAY nicer than the NetBeans ones.
Comment 10 neek 2013-01-21 10:37:46 UTC
I'd like to upvote this ticket somehow.  I don't feel the assignee, obrejla, understood the point, and it wasn't well explained by the original posters.

If I understand them right, they want a way to terminate execution of the PHP script that is being debugged.  When Netbeans attaches to a PHP script for debugging, the script is started, XDebug lets Netbeans connect to and control the execution of that script with typical step over, step into etc. commands, and examine its state.  However, there is no way of prematurely forcing that script to terminate, it must be allowed to run to its natural completion.

This can be a real problem if, for example, you see that it's about to do something you want to prevent (write bad data to your database, delete a file, whatever).  There is no debugger command to prevent this.  If you instigated the PHP script from a web browser, hitting Stop won't stop the execution of the script, just stop the browser waiting for a response.  Hitting the big red 'Finish Debugger Session' in Netbeans detaches Netbeans from the debugger session and lets the script continue execution.

I'm in that position right now, my PHP script is about to migrate hundreds of products between two databases, it's stopped at a breakpoint during debugging, and there's no way to stop it.  If this was a Java application, for example, I'd simply terminate the Java process being debugged and it wouldn't carry out its nefarious tasks.

The only way of stopping the script that I know of it to start killing processes on the host machine.  This is probably your web server, depending on what is hosting the PHP script.

Can someone comment on how hard it is to support a "Terminate process being debugged" action to Netbeans?  Does XDebug make this impossible?  I would understand if someone said that, due to the nature of the way XDebug works, it simply doesn't offer this capability, and so Netbeans cannot offer it.
Comment 11 Ondrej Brejla 2013-01-21 10:57:58 UTC
neek: I understand you. But I don't think that you are right. Try this snippet:

<?php
$a = "A";
$aa = "AA"; // set BP here
file_put_contents("./TEST", "This should not happen");
?>

If you set BP to that $aa line and run Debug File, XDebug stops at that BP Line. Then you click on that Red Square Button (Finish Debugger Session) in NB, then NO "TEST" file is created (if you run that file normally, it is created) because "stop" command is sent to XDebug and it terminates the execution of the script [1].

[1] http://xdebug.org/docs-dbgp.php#continuation-commands // stop command
Comment 12 neek 2013-01-21 11:03:42 UTC
Thanks for the reply obrejla .. I'm honestly surprised, you're right.  I've had this trouble many times in the past few years, that my database mangling scripts were unstoppable, but I tried it again just now and 'Finish debugger session' did prevent further execution of the script.

I shall eat my words with ketchup.

I guess this ticket remains valid, as there is no way to stop execution while holding the debugger session active, ready for a subsequent connection.
Comment 13 miked_187 2013-01-21 13:44:22 UTC
"I guess this ticket remains valid, as there is no way to stop execution while
holding the debugger session active, ready for a subsequent connection."

my workaround is to hit the 'start debugger' icon in the button bar again, NB will prompt with something like "debugger already running, restart?" where I will answer yes.  NB will halt current debug session and recreate a new one.  It's an extra step or 3 vs just hitting a halt button that would leave the debugger active.  Would still like to see a 'halt but leave active' option, or the ability to remove that confirmation window when you hit the debug icon as discussed above
Comment 14 neek 2013-01-21 15:05:33 UTC
> my workaround is to hit the 'start debugger' icon in the button bar again

That's a good trick Mike.  I presume you mean the 'Debug Main Project' button, by default just to the right of the 'Run Main Project' one?  I find I have up to 4 different PHP projects that I need to debug, and only one can be the 'Main Project' project at a time, so I continually have to open the Projects pane, find the project root node (which can be annoying enough with thousands of files in each), right click and 'Debug'.  It's pretty annoying.  Just hitting 'Debug Main Project' ends the current session and starts my Main Project, often not the one I was debugging a moment before.  To just be able to stop and restart the current session, or somehow latch it to the project that was being debugged last time, would be nice.

I'm very ignorant of how NB and XDebug work together so perhaps there's a nice trick I'm missing.
Comment 15 miked_187 2013-01-21 15:23:39 UTC
I may have added the icon to the button bar via Edit/Toolbars/Customize

Its the Ctrl-F5 button that when you hover over the tooltip says "Debug Project (prj name)"

"To just be able to stop and restart the current session, or somehow latch it to the project that was being debugged last time, would be nice."

You can slave debug sessions to specific projects by setting up a named debug session for each project.  Open Project pane, right click root node in the tree for the project, select Run Configuration, the name in the Configuration and the settings that go with it are specific to that project.  

Not sure if you can set the icon to debug a specific project from there -- ie icon/button 1 debugs project 1, icon/button 2 debugs project 2, but you could prob setup keyboard shortcuts to change the main prj from prj 1 to prj 2 to prj 3 pretty easily, then the debug session specifics you setup above will follow

I set mine as follows:

config name: as approp
run as: local
prj url: as approp
index: index file within this project

Hit advanced button

do not open webbrowser (this is the important one)

and then set my mappings as needed, I run NB on Win7 connecting to a Lunix VM over Samba so my settings will be specific to my config, but I set the pathing to the root of my webserver docs (/var/www/) and let NB interpret the mapping paths into the subfolders from there

In Tools/Options/PHP/Debugger I have 
port 9000
session_id: netbeans_xdebug

Break at first line: off
watches: off (really slows things down)

Not sure if you can set the icon to debug a specific project from there -- ie icon/button 1 debugs project 1, icon/button 2 debugs project 2, but you could prob setup keyboard shortcuts to change the main prj from prj 1 to prj 2 to prj 3 pretty easily, then the debug session specifics you setup above will follow.  Hope that makes sense, ping if you need more.