Jump to content
adrian

Tracy Debugger

Recommended Posts

I got the same issue as szabesz on Win, though I haven't checked it with the newest version.

  • Like 1

Share this post


Link to post
Share on other sites
However, it does open the compiled file in cache instead of the original ones.

Do you have any ideas why?

Hey guys,

I am not sure what is going on. To make this work I have made a small tweak to the Tracy core (hopefully only temporary as I have asked them about a way to publicly modify the filepath) - you can see it here: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/src/Tracy/Dumper.php#L111

Would you mind taking a look at that and debugging why it might not be working - just find out what $file contains before and after that str_replace

I can imagine on Windows I probably need to replace all the "/" with DIRECTORY_SEPARATOR but it sounds like @szabesz is on a Mac so what I have should work?

Thanks to both of you for helping out with this.

  • Like 1

Share this post


Link to post
Share on other sites

$file contains an empty string, but even before this line:

list($file, $line, $code) = $loc ? self::findLocation() : NULL;

I cannot seem to find any occurrence of $file before this line, so I suppose that is why it is empty in the first place.

  • Like 1

Share this post


Link to post
Share on other sites

list() populates the $file variable from the result of findLocation(), or NULL if $loc returns false. 

I am not sure what's going on, but if your edit links are to the compiled file, then it would suggest that $file is being populated. Could you maybe check the value of $loc and self::findLocation() before that list() call please?

  • Like 1

Share this post


Link to post
Share on other sites

$loc is 0

self::findLocation() :

Array
(
 [0] => .../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc
 [1] => 162
 [2] => Dumper::toHtml(\ProcessWire\wire('page'), array(Dumper::COLLAPSE => false))
)

EDIT: and similar values, since toHtml() gets called a lot of times...

Edited by szabesz
  • Like 1

Share this post


Link to post
Share on other sites

Is $loc always 0 ? If so, then that's the problem.

I get it 0 sometimes - when the first result of findLocation() is a module file. But when it's a template file, $loc returns 7

At least from this:

[0] => .../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc

I can see that the path in $file is matching something that the next line can remove the "/site/assets/cache/FileCompiler" component to make it the path to the original file.

Can you please clarify that $loc is always 0? What if you force it to 7 on line 100?

Thanks again for your help with this!

  • Like 1

Share this post


Link to post
Share on other sites

@matjazp: I tested with php 5.6, 5.5 and 5.4 and did not make a difference.

$loc is always 0. I put $loc = 7; on line 100 and I still get the compiled file. But this time:
Before the Tracy hack str_replace $file is:
.../site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc

after modifying the string we get:
.../site/modules/TracyDebugger/ProcesswireInfoPanel.inc

The above is 7 times, and we have "VariablesPanel.inc" 2 times at the end.

So "/site/assets/cache/FileCompiler" is removed as expected, but how is this path related to the my template file? Do not bother explaining it though, I was just wondering a bit :)

  • Like 1

Share this post


Link to post
Share on other sites

Thanks!

I am wondering what links are actually showing the compiled file? Can you show a screenshot of the link you are trying to click on?

Here are some examples showing it working as expected:

Link from a dump()

post-985-0-86435700-1457470273_thumb.png

Link from a barDump()

post-985-0-63403500-1457470274_thumb.png

I am starting to think you are talking about other links, but I am not sure what!

  • Like 1

Share this post


Link to post
Share on other sites

Oh, I see - I have been running in StrictMode, so haven't been noticing that - there is another location that I need to add that hack to change the path. I'll get that fix committed shortly.

@tpr - is this the case for you also? Do the links from dump() and barDump() calls get converted properly?

  • Like 1

Share this post


Link to post
Share on other sites

I have just tested and dump() and barDump() calls are ok. However, I have another question: Tracy\Debugger::dump(); and the others used to work but now I get:  Class 'ProcessWire\Tracy\Debugger' not found and Class 'ProcessWire\TD' not found   so only the shortcut methods work (ProcessWire 3.0.10 and the template file is in namespace ProcessWire; ).

Share this post


Link to post
Share on other sites

I can't test it right now but I also clicked on the link in the error panel.

  • Like 2

Share this post


Link to post
Share on other sites

I have just tested and dump() and barDump() calls are ok. However, I have another question: Tracy\Debugger::dump(); and the others used to work but now I get:  Class 'ProcessWire\Tracy\Debugger' not found and Class 'ProcessWire\TD' not found   so only the shortcut methods work (ProcessWire 3.0.10 and the template file is in namespace ProcessWire; ).

Great - thanks for confirming that the paths are correct for dump() and barDump()

The class not found error will be because of the template being the ProcessWire namespace. If you are doing that, then you'll need prepend a "\" to your calls, eg:

\Tracy\Debugger::dump('Test \Tracy\Debugger::dump');
\TD::dump('Test \TD::dump');

and then they'll work fine.

  • Like 1

Share this post


Link to post
Share on other sites

Ok, the latest version now correctly modifies the editor path to the file in the errors panel, as well as dump() and barDump().

Thanks again @szabesz for helping so much to figure this out - sorry we got so sidetracked along the way :)

  • Like 3

Share this post


Link to post
Share on other sites

That's okay. Happy to help :) Your Tracy Debugger module is a godsend!

  • Like 1

Share this post


Link to post
Share on other sites

@matjazp: I tested with php 5.6, 5.5 and 5.4 and did not make a difference.

In PHP 5, list() assigns the values starting with the right-most parameter. In PHP 7, list() starts with the left-most parameter. But I see that adrian fixed it...

  • Like 1

Share this post


Link to post
Share on other sites

I'm playing with Editor Protocol Handler set to "editor://open/?file=%file&line=%line" using UltraEdit. The problem I have is that editor won't open correct file if %line is empty string. So 

editor://open/?file=myfile.txt&line=1

is ok, while 

editor://open/?file=myfile.txt&line=

is not ok. This is bug in UltraEdit. Can you help by providing line number 1, if there is no line number?

  • Like 1

Share this post


Link to post
Share on other sites

Finally got the protocol handler thing to work on Win(8), thanks!

  • Like 2

Share this post


Link to post
Share on other sites
In PHP 5, list() assigns the values starting with the right-most parameter. In PHP 7, list() starts with the left-most parameter. But I see that adrian fixed it...

@matjazp - thanks for the info on the changes to list() in PHP 7 - I hadn't seen that yet, although from reading about it, I don't think it actually affects that code. 

This is bug in UltraEdit. Can you help by providing line number 1, if there is no line number?

No problem at all - I assume the only places where this is affecting you are the links to the template file from the PW Info panel (both in the template info section and the icon at the bottom)? Are there any other locations with links without line numbers that I haven't thought of?

Finally got the protocol handler thing to work on Win(8), thanks!

Awesome - care to share any tips for setting it up? Did you work with this file: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/tools/open-in-editor/open-editor.js

Thanks!

Share this post


Link to post
Share on other sites

Here's how I set up the editor protocol handler on Windows 8.

I started out using this but needed to modify a few things.

Note that I'm using a portable version of PhpStorm (using my own yaP launcher), so installed versions may need some modifications.

Module settings, "Editor protocol handler" field:

pstorm://open/?url=file://%file&line=%line

There's "editor.reg" file with these contents:

REGEDIT4

[HKEY_CLASSES_ROOT\pstorm]
@="URL:pstorm Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\pstorm\shell\open\command]
@="wscript \"D:\\portables\\PhpStorm\\run-editor.js\" \"%1\""

and also its counter-part, which removes registry key, "editor-unreg.reg":

REGEDIT4

[-HKEY_CLASSES_ROOT\pstorm]

The "editor.reg" needs to be merged to the registry - double click on it, or using regedit.exe and "Import" from the menu.

Note that you need to do this in admin mode, otherwise registry settings won't be added.

"editor-unreg" is only needed to clean the registry, possibly you won't ever need this.

Then you'll need a file named "run-editor.js" in the directory you've set in "editor.reg"

There's some hardcoded paths, project name and window title in the code below - these still need revisit.

"run-editor.js" file contents:

var settings = {
	// Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise.
	x64: true,

	// Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm')
	folder_name: 'PhpStorm 9.0',

	// Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance
	window_title: 'PhpStorm PS-145.61.14',

	// In case your file is mapped via a network share and paths do not match.
	// eg. /var/www will can replaced with Y:/
	projects_basepath: '/YOUR_PATH_HERE',
	projects_path_alias: 'D:/Projects/YOUR_PROJECT_NAME'
};

// don't change anything below this line, unless you know what you're doing
var	url = WScript.Arguments(0),
	match = /^pstorm:\/\/open\/\?url=file:\/\/(.+)&line=(\d+)$/.exec(url),
	project = '',
	editor = "D:\\portables\\PhpStorm\\PhpStormPortable.exe";

if (match) {

	var	shell = new ActiveXObject('WScript.Shell'),
		file_system = new ActiveXObject('Scripting.FileSystemObject'),
		file = decodeURIComponent(match[1]).replace(/\+/g, ' '),
		search_path = file.replace(/\//g, '\\');

	if (settings.projects_basepath != '' && settings.projects_path_alias != '') {
		file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias);
	}

	// note: uncomment to see the popup message (for testing)
	//shell.Popup(file, 0, "My Title", 64);

	while (search_path.lastIndexOf('\\') != -1) {
		search_path = search_path.substring(0, search_path.lastIndexOf('\\'));

		if(file_system.FileExists(search_path+'\\.idea\\.name')) {
			project = search_path;
			break;
		}
	}

	if (project != '') {
		editor += ' "%project%"';
	}

	editor += ' --line %line% "%file%"';

	var command = editor.replace(/%line%/g, match[2])
						.replace(/%file%/g, file)
						.replace(/%project%/g, project)
						.replace(/\//g, '\\');

	shell.Exec(command);
	shell.AppActivate(settings.window_title);
}

That's all. Clicking on a Tracy error line load PhpStorm at the file/line specified, and also brings the application to the front (activates it).

If you encounter errors, try to "debug" using popup messages (see "shell.Popup(..." line in the js file).

  • Like 4

Share this post


Link to post
Share on other sites
On 3/9/2016 at 3:47 PM, adrian said:

No problem at all - I assume the only places where this is affecting you are the links to the template file from the PW Info panel (both in the template info section and the icon at the bottom)? Are there any other locations with links without line numbers that I haven't thought of?

Yes, I was talking about template files.

On 3/9/2016 at 3:47 PM, adrian said:

Awesome - care to share any tips for setting it up? Did you work with this file: https://github.com/adrianbj/TracyDebugger/blob/master/tracy/tools/open-in-editor/open-editor.js

Huh, didn't know the file was there :-), I was using https://pla.nette.org/en/how-open-files-in-ide-from-debugger (link provided by @tpr) and modified just a little. My .js file is very simple, @tpr went few steps forward, here are the files:

editor.reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\editor]
@="URL:editor Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\editor\shell\open\command]
@="wscript //E:jscript \"D:\\editor.js\" \"%1\""

and editor.js:

// full path to the editor, you have to use double backslash
var editor = '"C:\\Program Files\\IDM Computer Solutions\\UltraEdit\\uedit64.exe" "%file%" -l%line%';

var url = WScript.Arguments(0);
var match = /^editor:\/\/open\/\?file=(.+)&line=(\d*)$/.exec(url);

if (match) {
    var file = decodeURIComponent(match[1]).replace(/\+/g, ' ').replace(/\//g, "\\");
    var command = editor.replace(/%line%/g, match[2]).replace(/%file%/g, file);
    var shell = new ActiveXObject("WScript.Shell");
    shell.Exec(command.replace(/\\/g, '\\\\'));
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your writeup also @matjazp - great to have this stuff documented!

I have committed a fix for the blank line number issue you were having. Please let me know if it works now.

New Feature

I have just added a new feature - it's a bit experimental, and I am not sure just how useful it is so would appreciate feedback.

It provides the ability to insert debugging statements (actually any code you want) at designtaed lines in the compiled template at runtime. I see this as useful if you want to quickly debug something on a live site without having to edit the files on the server.

In this example I am inserting two barDump (bd) statements into the home.php template file at lines 61 and 63 and noting which one is before the variable is iterated and which one is after. 

post-985-0-00563400-1457543595_thumb.png

The code for the home.php file looks like this:

post-985-0-29333000-1457543639_thumb.png

And this is the result in the dumps panel:

post-985-0-60835300-1457543721_thumb.png

Obviously the scenario and the inserted debug statements could be quite different, but hopefully you get the idea.

Note: Any lines of code inserted like this are only executed for superusers, so you could even use this as a way to insert lines of code that affect the output on the page without it affecting other users and guests.

Also, be sure to remove any statements when you are done debugging, because the template file is re-compiled every time the page is loaded when this field is populated.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...