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 Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory (alpha version only available via GitHub) SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By d'Hinnisdaël
      Happy new year, everybody 🥬
      I've been sitting on this Dashboard module I made for a client and finally came around to cleaning it up and releasing it to the wider public. This is how it looks.
      ProcessWire Dashboard

      If anyone is interested in trying this out, please go ahead! I'd love to get some feedback on it. If this proves useful and survives some real-world testing, I'll add this to the module directory.
      Download
      You can find the latest release on Github.
      Documentation
      Check out the documentation to get started. This is where you'll find information about included panel types and configuration options.
      Custom Panels
      My goal was to make it really simple to create custom panels. The easiest way to do that is to use the panel type template and have it render a file in your templates folder. This might be enough for 80% of all use cases. For anything more complex (FormBuilder submissions? Comments? Live chat?), you can add new panel types by creating modules that extend the DashboardPanel base class. Check out the documentation on custom panels or take a look at the HelloWorld panel to get started. I'm happy to merge any user-created modules into the main repo if they might be useful to more than a few people.
       Disclaimer
      This is a pre-release version. Please treat it as such — don't install it on production sites. Just making sure 🍇
      Roadmap
      These are the things I'm looking to implement myself at some point. The wishlist is a lot longer, but those are the 80/20 items that I probably won't regret spending time on.
      Improve documentation & add examples ⚙️ Panel types Google Analytics ⚙️ Add new page  🔥 Drafts 🔥 At a glance / Page counter 404s  Layout options Render multiple tabs per panel panel groups with heading and spacing between ✅ panel wrappers as grid item (e.g. stacked notices) ✅ Admin themes support AdminThemeReno and AdminThemeDefault ✅ Shortcuts panel add a table layout with icon, title & summary ✅ Chart panel add default styles for common chart types ✅ load chart data from JS file (currently passed as PHP array) Collection panel support image columns ✅ add buttons: view all & add new ✅
    • By Robin S
      This module is inspired by and similar to the Template Stubs module. The author of that module has not been active in the PW community for several years now and parts of the code for that module didn't make sense to me, so I decided to create my own module. Auto Template Stubs has only been tested with PhpStorm because that is the IDE that I use.
      Auto Template Stubs
      Automatically creates stub files for templates when fields or fieldgroups are saved.
      Stub files are useful if you are using an IDE (e.g. PhpStorm) that provides code assistance - the stub files let the IDE know what fields exist in each template and what data type each field returns. Depending on your IDE's features you get benefits such as code completion for field names as you type, type inference, inspection, documentation, etc.
      Installation
      Install the Auto Template Stubs module.
      Configuration
      You can change the class name prefix setting in the module config if you like. It's good to use a class name prefix because it reduces the chance that the class name will clash with an existing class name.
      The directory path used to store the stub files is configurable.
      There is a checkbox to manually trigger the regeneration of all stub files if needed.
      Usage
      Add a line near the top of each of your template files to tell your IDE what stub class name to associate with the $page variable within the template file. For example, with the default class name prefix you would add the following line at the top of the home.php template file:
      /** @var tpl_home $page */ Now enjoy code completion, etc, in your IDE.

      Adding data types for non-core Fieldtype modules
      The module includes the data types returned by all the core Fieldtype modules. If you want to add data types returned by one or more non-core Fieldtype modules then you can hook the AutoTemplateStubs::getReturnTypes() method. For example, in /site/ready.php:
      // Add data types for some non-core Fieldtype modules $wire->addHookAfter('AutoTemplateStubs::getReturnTypes', function(HookEvent $event) { $extra_types = [ 'FieldtypeDecimal' => 'string', 'FieldtypeLeafletMapMarker' => 'LeafletMapMarker', 'FieldtypeRepeaterMatrix' => 'RepeaterMatrixPageArray', 'FieldtypeTable' => 'TableRows', ]; $event->return = $event->return + $extra_types; }); Credits
      Inspired by and much credit to the Template Stubs module by mindplay.dk.
       
      https://github.com/Toutouwai/AutoTemplateStubs
      https://modules.processwire.com/modules/auto-template-stubs/
    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.60
      Composer: rockett/jumplinks
      ⚠️ NOTICE: 1.5.60 is an important security patch-release for an XSS vulnerability discovered by @phlp. It's HIGHLY RECOMMENDED that all Jumplinks users update to the latest version as soon as possible.
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! 🙂
    • By Robin S
      Add Image URLs
      Allows images/files to be added to Image/File fields by pasting URLs.

      Usage
      Install the Add Image URLs module.
      A "Paste URLs" button will be added to all image and file fields. Use the button to show a textarea where URLs may be pasted, one per line. Images/files are added when the page is saved.
       
      https://github.com/Toutouwai/AddImageUrls
      https://modules.processwire.com/modules/add-image-urls/
×
×
  • Create New...