ahungry / geben

Geben - PHP xdebug for Emacs
GNU General Public License v3.0
90 stars 10 forks source link

vm/docker integration for file mapping #11

Closed ksjogo closed 7 years ago

ksjogo commented 8 years ago

Vm/docker integration for file mapping would be helpful for editing original file and the file find functions.

ksjogo commented 7 years ago

Proposal: Add a customization for a list of string string pairs Do a simple string substituation on set breakpoint when not in geben-mode and set the breakpoint on the matched file. @ahungry Ok for you?

ahungry commented 7 years ago

Sounds like a good idea!

bipol-cb commented 7 years ago

Is there a way I can get around this currently? I'm having trouble with the workflow : Set a breakpoint in a file, run until I hit this breakpoint.

mallt commented 7 years ago

@bipol-cb M-x geben-add-current-line-to-predefined-breakpoints should allow you to set a breakpoint in a file outside of an active geben session. The breakpoint will be hit during the next geben session. Would this fit your needs?

bipol-cb commented 7 years ago

@mallt Yup - I think that will do it. I can see that the breakpoints are being made, but unfortunately are never being hit. Not sure if this is due to the fact that the webserver is running in docker, so the files mounted in the container have a different path than the ones locally?

-- Also, sorry if this is the wrong place for this conversation. Should I make a separate issue ( this is less of an issue than my own misunderstanding ).

ksjogo commented 7 years ago

Yes, geben will store the path. So that is exactly the right issue. Adding a simple replacement right now.

mallt commented 7 years ago

@bipol-cb Ok now I see, no, this approach would currently only work for local files. I'm not familiar with docker but if you have access to the paths of the files in the docker container you might be able to customize the geben-predefined-breakpoints variable by adding the docker paths instead of the local paths:

(setq geben-predefined-breakpoints '(("full-docker-path" . line-number)))

But I'm not sure only this change would be enough to make it work.

@ksjogo When rereading this thread I guess this would be in the direction of your approach of using the docker paths instead of the local paths, is that correct?

ksjogo commented 7 years ago

Just pushed and tested with a local docker, customize geben-path-mappings e.g. (setq geben-path-mappings '(("/Users/dkd-goslar/dkd/t3_semantic_eye_docker/" "/var/www/html/"))) And it will then work with docker. No reverse yet though (for opening original file).

mallt commented 7 years ago

@ksjogo Thanks!

Just a remark concerning the reverse for opening the original file: we could also keep the local filenames in the geben-predefined-breakpoints variable and move the mapping logic to the geben-set-predefined-breakpoints function (this is where the "real" breakpoints are set in the geben session).

This way after clearing the geben-path-mappings variable the local breakpoints would be preserved.

I'm not sure however how often this behavior would be needed (switching back to the local files), so the current implementation might be more than sufficient.

keisetsu commented 7 years ago

I'm not sure if this is exactly related, as I'm really unfamiliar with geben, but it sounds like what I want to do. I have a vagrant vm running, using files from the host system for a symfony app. I've gotten as far as M-x geben, which does connect to the xdebug server, but I can't seem to set a breakpoint on any files outside those that I can step through to, using M-x geben-add-current-line-to-predefined-breakpoints as mentioned above, putting a file in geben-mode and then trying to use B, or any other method. Is there a straightforward way to do this? Sorry, I'm just completely lost.

ksjogo commented 7 years ago

If you require some path mapping from local files to vagrant vm you can now customize geben-path-mappings, so you should do something like M-x customize-variable geben-path-mappings, then click INS, add some fully qualified local path like /home/ksjogo/dev/myproject as first value and the respective remote path like /vagrant/myproject as second value. Then save that. Geben will (should?) then map these paths accordingly.

keisetsu commented 7 years ago

Thanks for your reply! I'm still not getting it. I have done that, but when I try to open a file using C-c f, it provides /vagrant/..., and if I copy and paste the folder that it should be in, it says "no match". If I try /home/myname/project/git/ and the same path instead, it is able to find the file I want with tab completion and everything, but if I hit enter it says "Command error: cannot open file".

ksjogo commented 7 years ago

Are you trying to open a file from within the debugging session? For geben-find-file the path mapping is not implemented yet. Only local->remote for setting breakpoints yet as that is what I use only. I could look into adding remote->local next week when back in the office though. Still you could just open the real files directly from emacs/standard find-file. Another important point to notice is that geben is not presenting the real file anyway, but a readonly copy to have safe and stable line numbers.

keisetsu commented 7 years ago

All I want to do is set a breakpoint and have it stop there. Opening the file directly (C-x C-f), calling M-x geben-add-current-line-to-predefined-breakpoints, then M-x geben, loading the page in the browser and geben stops at what looks like the first step. If I just do a geben-run then, it just runs all the way through from there, not stopping at the breakpoint. I've also stepped through every step (and there are an amazing number of them!), and it just shows the symfony/vendor files, none of the project files.

I'm sure it's clear I have no idea what I'm doing.

ksjogo commented 7 years ago

Ok, two things here: Could you check the value of geben-predefined-breakpoints and see if the right file is in it? Which symfony calls are you using? If you call some specific symfony wrapper stuff symfony will create another PHP process which try to open another xdebug/geben session which will be rejected as another on the same port is open. Solvable by adding the symfony wrapper file entry point to the geben skip list. If the code itself is creating another process you could do a counted skip. All that functionality only got recently added to geben as I needed it for TYPO3 debugging and not well/really documentated, but I am happy to help here. Should probably also do some vids for recent geben features. Do you have some example project which I could try to hit break points in?

keisetsu commented 7 years ago

Well, wouldn't you know it, I tried it again and it seems to be working! Yippee! I must have had the directory mapping incorrectly set up. Thanks!

ksjogo commented 7 years ago

Great. I will close that for now as the most important thing is in now.

keisetsu commented 7 years ago

geben-path-mappings seems to have disappeared in the latest release on MELPA?

ksjogo commented 7 years ago

Shouldn't have. Also doing package-install geben and opening that geben.el file will show the defcustom for geben-path-mappings. Which version from melpa gets installed on your machine?

keisetsu commented 7 years ago

Sorry, I didn't realize I had to start geben before the customization would appear. It is there. Still just can't seem to get it to work (worked once, but I can't seem to get any other breakpoints to stick). Ah, I'm using xdebug 2.2.3, maybe that's the problem? Although everything seems to work, just adding breakpoints fails (and that worked once, like I said).

ksjogo commented 7 years ago

What's your value of geben-path-mappings? And what will show up in geben-predefined-breakpoints after trying to set a breakpoint?

keisetsu commented 7 years ago

Ah, ok, I was able to get another breakpoint defined. I don't really know why it didn't work yesterday.

I do see now one thing I didn't understand: Among many other things, I was trying to define a breakpoint in the buffer that geben opens to show current progress (which is in geben's storage?), but I guess I have to define it in the original file, correct? Ah, so I can set the breakpoint in the stored file using b/geben-set-breakpoint-line! I think I'm getting it.

One area I get confused: once geben has run through once, the buffer shown is no longer useful, as far as I can tell. I thought I could add breakpoints at any time and was getting confused when the breakpoints didn't show up on an older buffer. But I guess I can only set access the geben commands in an active geben buffer? I understand I can always use the predefined breakpoints command.

I have to say, once I get past these first steps, geben is insanely useful. Hopefully I won't have further problems. It might be helpful to document these steps, so you can avoid having to waste time with noobies like me!

  1. Add a mapping from files on the host to files on the vm/docker image with M-x customize-variable geben-path-mappings or set in emacs config with (setq geben-path-mappings '(("<project base on host>" "<project base on vm>"))) 1.5. Check those mappings with C-h v geben-path-mappings. The mappings may not (?) show up until a geben process is running.
  2. Open a file you are interested in setting breakpoints on the host machine. Find the breakpoint and issue M-x geben-add-current-line-to-predefined-breakpoints. 2.5 Check that a breakpoint has been set with C-h v geben-predefined-breakpoints
  3. Run the geben process: M-x geben.
  4. Initiate the xdebug server.
  5. Use r or C-c C-c until you reach your breakpoint.
  6. To set new breakpoints in an active geben buffer, you can use b or M-x geben-set-breakpoint-line. To set a new breakpoint outside an active geben buffer, open the file on the host system and use M-x geben-add-current-line-to-predefined-breakpoints again.
ksjogo commented 7 years ago

Added a section for VMs and restructured the README at https://github.com/ahungry/geben/tree/readme

bridgesense commented 7 years ago

I'm a recent convert to Emacs and am really enjoying the performance boost. I am in the processes of pulling together familiar tools I have in Vim when I stumbled over Geben. I spent hours making friends with Geben. I probably would have tossed it if I hadn't found this thread.

I use VM's because they are quick and safe, but to step through 40 to 60 files to get to the problem child is a step backwards. Luckily I found this thread. My visits to Xdebug are usually pretty brief.

I would push the document changes and really highlight the mapping device because everyone who's used vDebug or Xdebug in Sublime is looking for it.

I've setup General in my dot, and I'd love to be able to pull up the customize-variable geben-path-mappings screen with a hot key. Any suggestions? Right now I'm part of the way there.

  ;; Geben Functions
  ;; See Reference: https://github.com/ahungry/geben/tree/readme#VMs
  (general-define-key
   :states '(normal motion insert emacs)
   :prefix gleader
   :non-normal-prefix gleader-non
   "g"  '(nil :which-key "Geben (DBGp)")
   "gb" '(geben-add-current-line-to-predefined-breakpoints :which-key "(2) Add Breakpoint")
   "gc" '(geben-clear-predefined-breakpoints :which-key "Clear Breakpoints")
   "gm" '(customize-variable :which-key "(1) set geben-path-mappings")
   "go" '(geben :which-key "(3) Start Geben")
   "gr" '(geben-run :which-key "(4) Continue to Breakpoint")
   "gx" '(geben-end :which-key "Stop Geben"))
ksjogo commented 7 years ago

I am happy to here that it was some performance boost but would be interested compared to which tool that was. Merged the updated readme.

"gm" '((lambda () (interactive) (customize-variable 'geben-path-mappings)) :which-key "(1) set geben-path-mappings") should work

bridgesense commented 7 years ago

Thanks for the code. That worked. I'm a little hazy on the (interactive) item. I'll have to check that out.

The performance boost is generally with Emacs itself. When I can open a gig sized file in less than a second and see that syntax is already applied -- I was sold. vDebug is a tool I do use frequently. So I wouldn't have made the transition to Emacs without Geben.

Thanks.