Commit 1222ee72 authored by Andrey Filippov's avatar Andrey Filippov

added debugfs-webgui

parent a2e29be3
# Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src/php_top src/python_tests # src1
SUBDIRS := src/php_top src/python_tests src/debugfs-webgui # src1
INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%)
......
DOCUMENTROOT=$(DESTDIR)/www/pages
OWN = -o root -g root
INSTDOCS = 0644
INSTALL = install
DOCS= debugfs.html \
debugfs.css \
debugfs.js
PHP_SCRIPTS=debugfs.php
all:
@echo "make all in src"
install:
@echo "make install in src"
$(INSTALL) $(OWN) -d $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(DOCS) $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(PHP_SCRIPTS) $(DOCUMENTROOT)
clean:
@echo "make clean in src"
html{
font-family: Arial;
font-size: 0.8em;
}
body{
padding: 10px;
}
table{
border-collapse:collapse;
border-radius: 3px;
}
th, td{
text-align: left;
padding: 3px 10px 3px 10px;
border-radius: 0px;
border: 1px solid rgba(180,180,180,0.5)
}
th {
background-color: rgba(200,200,200,0.5);
}
.even {
background-color: rgba(235,235,235,0.5);
}
.odd {
background-color: rgba(255,255,255,0.5);
}
.special {
background-color: rgba(100,200,100,0.5);
}
select {
border: 1px solid rgba(200,200,200,1);
border-radius: 2px;
font-family: Arial;
font-size: 1em;
background-color: rgba(200,200,200,0.5);
margin: 0px;
padding: 1px;
}
input {
-moz-appearance: none;
border: 1px solid rgba(200,200,200,1);
}
.tp{
width:20px;
height:20px;
}
\ No newline at end of file
<html>
<head>
<script src="js/jquery-2.2.3.min.js"></script>
<script src="debugfs.js"></script>
<script src="js/bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="js/bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="debugfs.css"/>
</head>
<body onload='init()'>
</body>
</html>
\ No newline at end of file
var debugfs_data;
function init(){
$("body").html("<h3>DebugFS:</h3>");
var b0 = $("<button>",{id:"b0"}).html("toggle hidden");
b0.prop("state",0);
b0.click(function(){
if ($(this).prop("state")==0){
$(this).prop("state",1)
$(".hidden_rows").show();
}else{
$(this).prop("state",0)
$(".hidden_rows").hide();
}
});
$("body").append($("<div>").css({padding:"0px 0px 10px 0px"}).append(b0));
var t = $("<table border=\"1\">").html("\
<tr>\
<th style='display:none;' class='hidden_rows'>Show</th>\
<th>File</th>\
</tr>\
");
$("body").append(t);
$.ajax({
url: "debugfs.php",
success: function(data){
var r = jQuery.parseJSON(data);
//global
debugfs_data = r;
for(var i=0;i<r.length;i++){
l = $("<tr>",{id:"row_"+i}).html("\
<td class='hidden_rows' style='text-align:center;display:none' >\
<input id='cb_"+i+"' class='tp visibility_cb' type='checkbox'>\
</td>\
<td class='special filename' id='header_"+i+" '>"+r[i].file+"</td>\
");
if (r[i].state==0){
l.addClass("hidden_rows").hide();
l.find("input").prop("checked",false);
}else{
l.removeClass("hidden_rows").show();
l.find("input").prop("checked",true);
}
content = $("<tr>",{
id: "content_"+i
}).css({
display: "none",
border: "0px solid rgba(255,255,255,0)"
});
content.append(
$("<td>").addClass("hidden_rows").hide()
).append(
$("<td>").append(
$("<table>").css({margin:"5px"})
)
);
//.append($("<td>").addClass("hidden_rows").css({display:"none"}))
t.append(l).append(content);
var r1 = r[i].configs[0].lines;
for (var j=0;j<r1.length;j++){
ttl = "module: "+r1[j].module+"\n";
ttl += "function: "+r1[j].function+"\n";
ttl += "format: "+r1[j].format;
if (r1[j].flags=="p"){
checked = "checked";
}else{
checked = "";
}
l = "<tr>";
l += " <td style='text-align:center' title='"+ttl+"'>"+r1[j].lineno+"</td>";
l += " <td style='text-align:center'><input type='checkbox' class='tp debug' "+checked+" file='"+r1[j].file+"' line='"+r1[j].lineno+"' /></td>";
l += "</tr>";
content.find("table").append(l);
}
}
//init actions
$(".debug").change(function(){
console.log($(this).attr("file")+", "+$(this).attr("line")+", "+$(this).prop("checked"));
$.ajax({
url: "debugfs.php?cmd=echo&file="+$(this).attr("file")+"&line="+$(this).attr("line")+"&pflag="+$(this).prop("checked")
});
});
$(".filename").click(function(){
var id = $(this).attr("id");
id = id.substr(id.indexOf("_")+1);
console.log(id);
$("#content_"+id).toggle();
});
$(".visibility_cb").change(function(){
var id = $(this).attr("id");
id = id.substr(id.indexOf("_")+1);
if ($(this).prop("checked")){
$("#row_"+id).removeClass("hidden_rows");
debugfs_data[id].state = 1;
}else{
$("#row_"+id).addClass("hidden_rows");
$("#content_"+id).hide();
debugfs_data[id].state = 0;
}
update_debugfs_config();
});
//when everything is parsed. do something.
// unique IDs
// save config
}
});
}
function update_debugfs_config(){
console.log("syncing debugfs config");
console.log(debugfs_data);
$.ajax({
type: "POST",
url: "debugfs.php?cmd=sync",
data: JSON.stringify(debugfs_data),
dataType: "json"
});
}
<?php
if (isset($_GET['cmd']))
$cmd = $_GET['cmd'];
else
$cmd = "do_nothing";
function get_control($f){
$res = Array();
$results = trim(file_get_contents($f));
//print("<pre>");
$ress = explode("\n",$results);
//filename - find first ":"
//lineno - between ":" and " "
//then [module] inside brackets
//function from "]" to " "
$oldfile = "";
foreach($ress as $line){
if ($line[0]=="#") continue;
$d0 = 0;
$d1 = strpos($line,":");
$d2 = strpos($line,"[");
$d3 = strpos($line,"]");
preg_match("/=[flmpt_]+/",$line,$matches,PREG_OFFSET_CAPTURE);
$d4 = $matches[0][1];
$d5 = strpos($line,"\"");
$subarr = Array();
$subarr['file'] = substr($line,0,$d1);
$subarr['lineno'] = substr($line,$d1+1,($d2-1)-$d1-1);
$subarr['module'] = substr($line,$d2+1,($d3-1)-$d2);
$subarr['function'] = substr($line,$d3+1,($d4-1)-$d3);
$subarr['flags'] = substr($line,$d4+1,1);
$subarr['format'] = substr($line,$d5+1,-1);
if ($subarr['file']!=$oldfile){
echo "processing ".$subarr['file']."\n";
if ($oldfile!="") array_push($res,$sub);
$oldfile = $subarr['file'];
$sub = Array(
"file" => $subarr['file'],
"state" => 0,
"configs" => Array(
Array(
"name" => "default",
"state" => 1,
"lines" => Array()
)
)
);
}
array_push($sub['configs'][0]['lines'],$subarr);
}
//last
array_push($res,$sub);
return $res;
}
function update_config($data){
// debugfs.json
file_put_contents("debugfs.json",$data);
}
function sync_to_config($file,$line,$flag){
//$arr_debugfs = get_control("/sys/kernel/debug/dynamic_debug/control");
$arr_config = json_decode(file_get_contents("debugfs.json"),true);
foreach($arr_config as $k => $v){
if ($v['file']==$file) $dc = $k;
}
echo "DC=$dc\n";
$tmp_arr1 = $arr_config[$dc]['configs'];
foreach($tmp_arr1 as $k => $v){
if ($v['state']==1) $dcc = $k;
}
$tmp_arr2 = $arr_config[$dc]['configs'][$dcc]['lines'];
foreach($tmp_arr2 as $k => $v){
if ($v['lineno']==$line) $dccc = $k;
}
if ($flag=="+") $flag = "p";
else $flag = "_";
$arr_config[$dc]['configs'][$dcc]['lines'][$dccc]['flags'] = $flag;
print_r($arr_config);
update_config(json_encode($arr_config));
}
if (($cmd=="do_nothing")||($cmd=="restore")){
if (isset($_GET['file'])) $file = $_GET['file'];
else $file = "/sys/kernel/debug/dynamic_debug/control";
//echo json_encode(get_control($file));
//echo "<pre>";
if (!is_file("debugfs.json")) {
$arr = get_control($file);
print_r($arr);
update_config(json_encode($arr));
echo "debugfs.json was missing, refresh page\n";
}else{
$json_data = file_get_contents("debugfs.json");
//print_r(json_decode($json_data));
echo $json_data;
}
}
if ($cmd=="echo") {
$file = $_GET['file'];
$line = $_GET['line'];
$flag = $_GET['pflag'];
//$config name
if ($flag=="true"){
$flag="+";
}else{
$flag="-";
}
exec("echo -n 'file $file line $line ${flag}p' > /sys/kernel/debug/dynamic_debug/control");
sync_to_config($file,$line,$flag);
}
$debugfs_configs = "debugfs_configs";
if ($cmd=="save"){
$file = $_GET['file'];
if (!is_dir($debugfs_configs)) mkdir($debugfs_configs);
file_put_contents("$debugfs_configs/$file", file_get_contents("/sys/kernel/debug/dynamic_debug/control"));
}
if ($cmd=="sync"){
//list saved configs here
$data = file_get_contents("php://input");
update_config($data);
}
//single line: echo -n 'file gamma_tables.c +p' > /sys/kernel/debug/dynamic_debug/control
?>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment