Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

xdebug 2.2 fixes a bug that makes it possible to link to function/met…

…hod definitions

Enable links directly to function definitions if xdebug version is greater than or equal to 2.2.
  • Loading branch information...
commit 44878d1b34a540556870e3ee68e4c1409bff020e 1 parent ffb7cad
@oetting oetting authored
Showing with 27 additions and 9 deletions.
  1. +4 −0 index.php
  2. +16 −6 library/Reader.php
  3. +7 −3 templates/index.phtml
View
4 index.php
@@ -87,6 +87,10 @@ class Webgrind_MasterConfig
$result['runs'] = $reader->getHeader('runs');
$result['breakdown'] = $breakdown;
$result['mtime'] = date(Webgrind_Config::$dateFormat,filemtime(Webgrind_Config::xdebugOutputDir().$dataFile));
+
+ $version = preg_replace('/[^0-9\.]/', '', $reader->getHeader('creator'));
+ $result['linkToFunctionLine'] = version_compare($version, '2.2') > 0;
+
echo json_encode($result);
break;
case 'callinfo_list':
View
22 library/Reader.php
@@ -28,7 +28,12 @@ class Webgrind_Reader
*/
const CALLINFORMATION_LENGTH = 4;
- /**
+ /**
+ * Length of a function information block
+ */
+ const FUNCTIONINFORMATION_LENGTH = 6;
+
+ /**
* Address of the headers in the data file
*
* @var int
@@ -103,7 +108,7 @@ function getFunctionCount(){
function getFunctionInfo($nr){
$this->seek($this->functionPos[$nr]);
- list($summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(5);
+ list($line, $summedSelfCost, $summedInclusiveCost, $invocationCount, $calledFromCount, $subCallCount) = $this->read(self::FUNCTIONINFORMATION_LENGTH);
$this->seek(self::NR_SIZE*self::CALLINFORMATION_LENGTH*($calledFromCount+$subCallCount), SEEK_CUR);
$file = $this->readLine();
@@ -111,6 +116,7 @@ function getFunctionInfo($nr){
$result = array(
'file'=>$file,
+ 'line'=>$line,
'functionName'=>$function,
'summedSelfCost'=>$summedSelfCost,
'summedInclusiveCost'=>$summedInclusiveCost,
@@ -132,8 +138,12 @@ function getFunctionInfo($nr){
* @return array Called from information
*/
function getCalledFromInfo($functionNr, $calledFromNr){
- // 5 = number of numbers before called from information
- $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*(self::CALLINFORMATION_LENGTH*$calledFromNr+5));
+ $this->seek(
+ $this->functionPos[$functionNr]
+ + self::NR_SIZE
+ * (self::CALLINFORMATION_LENGTH * $calledFromNr + self::FUNCTIONINFORMATION_LENGTH)
+ );
+
$data = $this->read(self::CALLINFORMATION_LENGTH);
$result = array(
@@ -156,8 +166,8 @@ function getCalledFromInfo($functionNr, $calledFromNr){
* @return array Sub call information
*/
function getSubCallInfo($functionNr, $subCallNr){
- // 4 = number of numbers before sub call count
- $this->seek($this->functionPos[$functionNr]+self::NR_SIZE*3);
+ // Sub call count is the second last number in the FUNCTION_INFORMATION block
+ $this->seek($this->functionPos[$functionNr] + self::NR_SIZE * (self::FUNCTIONINFORMATION_LENGTH - 2));
$calledFromInfoCount = $this->read();
$this->seek( ( ($calledFromInfoCount+$subCallNr) * self::CALLINFORMATION_LENGTH + 1 ) * self::NR_SIZE,SEEK_CUR);
$data = $this->read(self::CALLINFORMATION_LENGTH);
View
10 templates/index.phtml
@@ -39,7 +39,7 @@
$("#function_table tbody").empty();
for(i=0;i<data.functions.length;i++){
callInfoLoaded[data.functions[i].nr] = false;
- $("#function_table tbody").append(functionTableRow(data.functions[i]));
+ $("#function_table tbody").append(functionTableRow(data.functions[i], data.linkToFunctionLine));
}
currentDataFile = data.dataFile;
$("#data_file").html(data.dataFile);
@@ -185,11 +185,15 @@
}
}
- function functionTableRow(data){
+ function functionTableRow(data, linkToFunctionLine){
if (data.file=='php%3Ainternal') {
openLink = '<a title="Lookup function" href="<?php echo ini_get('xdebug.manual_url')?>/'+data.functionName.substr(5)+'" target="_blank"><img src="img/file.png" alt="O"></a>';;
} else {
- openLink = '<a title="Open file" href="'+sprintf(fileUrlFormat,data.file,-1)+'" target="_blank"><img src="img/file.png" alt="O"></a>';
+ if(linkToFunctionLine){
+ openLink = '<a title="Open file and show line" href="'+sprintf(fileUrlFormat, data.file, data.line)+'" target="_blank"><img src="img/file_line.png" alt="O"></a>';
+ } else {
+ openLink = '<a title="Open file" href="'+sprintf(fileUrlFormat, data.file, -1)+'" target="_blank"><img src="img/file.png" alt="O"></a>';
+ }
}
return '<tr> \
<td> \
Please sign in to comment.
Something went wrong with that request. Please try again.