Kint's traceback currently looks like this:

[+]Called from <ROOT>/modules/devel/devel.module:657 [kprint_r()]

and expanded:

[–]Called from <ROOT>/modules/devel/devel.module:657 [kprint_r()]
1. <ROOT>/modules/devel/devel.module:594 [kprint_r()]
2. <ROOT>/modules/.../src/Plugin/Block/DnaBlock.php:1082 [dpm()]
3. <ROOT>/modules/.../src/Plugin/Block/DnaBlock.php:261 [Drupal\...\DnaBlock::format_row()]
4. <ROOT>/modules/.../src/Form/DnaForm.php:57 [Drupal\...\DnaBlock::buildNodeInfo()]
5. <ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:517 [call_user_func_array()]
6. <ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:276 [Drupal\Core\Form\FormBuilder->retrieveForm()]
...

The first issue is that the top line is completely useless. We're not in the least interested in kprint_r() and dpm(). Kint takes care of removing itself from the stack, but it should allow the caller (us) to remove itself, too, if it wants to be useful as a building block. I've tried to implement passing a number of stack frames to pop to Kint::dump() and d() (!), but somehow it's not working right...

The second issue is that the function names are off by 1. I don't want to know that
DnaBlock.php:1082 is calling dpm() but rather that
DnaBlock.php:1082 is in the function DnaBlock::format_row().

Or, from the other side, when I look through the function names on the stack, and I find DnaBlock::format_row() as the function that I want to open in my editor, then I expect to see the file/line number of that function at the same stack level, not at the one above it.

So, IMHO this should look like:

[–]Called from <ROOT>/modules/.../src/Plugin/Block/DnaBlock.php:1082 [Drupal\...\DnaBlock::format_row()]
1. <ROOT>/modules/.../src/Plugin/Block/DnaBlock.php:261 [Drupal\...\DnaBlock::buildNodeInfo()]
2. <ROOT>/modules/.../src/Form/DnaForm.php:57 [call_user_func_array()]
3. <ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:517 [Drupal\Core\Form\FormBuilder->retrieveForm()]
4. <ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:276 [Drupal\Core\Form\FormBuilder->buildForm()]
...

Am I the only one who feels that way?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis created an issue. See original summary.

joachim’s picture

Title: Fix dpm()'s / Kint's backtrace » dpm()'s / Kint shows the file and line from devel module, not from where dpm() was called

Clearer title.

joachim’s picture

This looks like it's a limitation of Kint, as it's code in there that gets a backtrace -- or we should be passing it something which we're not.

joachim’s picture

joachim’s picture

I've had feedback on that issue I filed on Kint.

Basically, we should be setting Kint::$aliases, so it can correctly determine that things like dsm(), dpm() should be trimmed from the backtrace.

However, I've tried two ways of doing this and neither is giving completely correct results.

1. Adding this to kprint_r() doesn't work:

      Kint::$aliases += [
  			'dsm',
  			'dpm',
  			'kprint_r',
      ];

2. Adding this to the Kint class directly works for the backtrace, but then suddenly the kint output is in the wrong block!

	public static $aliases = array(
		'methods'   => array(
			array( 'kint', 'dump' ),
			array( 'kint', 'trace' ),
		),
		'functions' => array(
			'd',
			'dd',
			's',
			'sd',
			'dsm',
			'dpm',
		)
	);
joachim’s picture

Ah, got it without having to hack Kint itself:

      Kint::$aliases['functions'] = array_merge(Kint::$aliases['functions'], [
  			'dsm',
  			'dpm',
  			'kprint_r',
      ]);

But that is still causing the output to go in the wrong region!

AaronBauman’s picture

+1 for this.
It's completely useless to see the 3 devel-related functions at the top of the backtrace.

Where did you add the aliases?

AaronBauman’s picture

OK, found it.
Following up from the github thread, you just need to set the $returnOutput flag on Kint to make sure dump returns a string instead of emitting it.

Here's a patch, which undoubtedly needs work but accomplishes the request without hacking Kint.

Maintainers:
please advise about a better place to put the aliases.
Maybe in the constructor?

willzyx’s picture

@aaronbauman thanks for the patch!

please advise about a better place to put the aliases.

The idea is to add a method in the DevelDumperBase that returns a list of methods and function considered internal for the dumper system. In this way all dumper plugins can access and use these informations see #2712489: Exclude internal functions from backtrace

AaronBauman’s picture

Status: Needs review » Closed (duplicate)
Parent issue: » #2712489: Exclude internal functions from backtrace

OK cool, i'll mark this as duplicate then.

AaronBauman’s picture

Status: Closed (duplicate) » Postponed

Hmm, actually postponed makes more sense, since I see the referenced patch provides an API but does not actually address the output.
Did you have an approach in mind for suppressing these internal functions from the backtrace?

willzyx’s picture

Did you have an approach in mind for suppressing these internal functions from the backtrace?

Something like

\Kint::$aliases = array_merge_recursive(\Kint::$aliases, $this->getInternalAliases());
\Kint::$returnOutput = TRUE;

should be ok

joachim’s picture

Postponed or not, I can confirm the patch in #8 fixes the problem! Thanks!

joachim’s picture

Rerolled patch.

I know that once #2712489: Exclude internal functions from backtrace this will need reworking again, but dpm() is far less useful with this broken.

Changing the code from using ob_start() to \Kint::$returnOutput = TRUE; should probably happen in another issue.

joachim’s picture

\Kint::$aliases = array_merge_recursive(\Kint::$aliases, $this->getInternalAliases());

is sufficient with the patch from #2712489: Exclude internal functions from backtrace applied.

However, it conceals the message from a kint backtrace!

\Kint::$returnOutput = TRUE;

causes no kint output to be shown at all.

Ben Buske’s picture

The parent issue is now solved (to be ported). Does someone know if this issue is still relevant?

moshe weitzman’s picture

Status: Postponed » Closed (duplicate)

I think this got fixed. Please use v3 branch