修改bug

This commit is contained in:
Your Name 2022-11-07 17:21:23 +08:00
parent 09c4c89216
commit bc916e1153
3 changed files with 55 additions and 46 deletions

View File

@ -28,14 +28,9 @@ do
fi
done
if [ ! -e /proc/$1 ];then
echo "Pid not exist"
exit 103
fi
if [ ! -e /proc/$1/exe ];then
echo "Process exe not exist"
exit 105
exit 103
fi
LIBPTHREAD_PATH=`ldd /proc/$1/exe | grep pthread | awk '{print $3}'`
@ -44,4 +39,6 @@ if [ -z "${LIBPTHREAD_PATH}" ];then
exit 104
fi
echo "/proc/$1/root${LIBPTHREAD_PATH}|$1"
BINPATH=`readlink /proc/$1/exe`
echo "/proc/$1/root${LIBPTHREAD_PATH}|${BINPATH}|$1"

View File

@ -2,7 +2,6 @@ import * as vscode from 'vscode';
import * as child from 'child_process';
import {execDetect, testPwd, prase_yaml2html} from './utils';
import { dirname, join } from 'path';
import { kill } from 'process';
import * as fs from 'fs';
const checkTool: string = join(dirname(__dirname), "detect-tools/pidcheck.sh");
@ -21,10 +20,9 @@ function execCheckTool(pwd: string, checkedPid: number, cb: (code: number, da:st
});
}
function createTerm(checkedPid:number, task: child.ChildProcess): vscode.Pseudoterminal {
function createTerm(checkedPid:number, passwd: string, task: child.ChildProcess): vscode.Pseudoterminal {
const writeEmitter = new vscode.EventEmitter<string>();
const closeEmitter = new vscode.EventEmitter<number>();
var intervalObj: NodeJS.Timer;
const pty: vscode.Pseudoterminal = {
onDidWrite: writeEmitter.event,
onDidClose: closeEmitter.event,
@ -36,15 +34,15 @@ function createTerm(checkedPid:number, task: child.ChildProcess): vscode.Pseudot
intervalObj = setInterval(intervalFunc, 1500, writeEmitter);
},
close: () => {
task.kill(9);
child.execSync(`echo ${passwd} | sudo -S killall -2 deadlockcheck`);
closeEmitter.fire(0);
},
handleInput: data => {
if (data === 'q') {
writeEmitter.fire(`\r\n停止进程${checkedPid}锁分析\r\n`);
clearInterval(intervalObj);
task.kill(9);
// closeEmitter.fire(0);
console.log(task.pid);
child.execSync(`echo ${passwd} | sudo -S killall -2 deadlockcheck`);
}
}
};
@ -54,15 +52,46 @@ function createTerm(checkedPid:number, task: child.ChildProcess): vscode.Pseudot
function localPidAnalyse(pid: number, passwd:string, context: vscode.ExtensionContext) {
// var term = new MyCustomBuildTaskTerminal(pid);
// term.open(undefined);
var binPath = fs.readlinkSync(`/proc/${pid}/exe`, {encoding:'utf-8'});
let task = execCheckTool(passwd, pid, (code, out)=>{
if(out.length){
if(out.match(/fatal/)?.length){
execCheckTool(passwd, pid, (code, out)=>{
if(out.length === 0){
switch (code) {
case 99:
vscode.window.showWarningMessage("当前已存在检测任务,请稍后再试");
case 100:
vscode.window.showWarningMessage("当前Kernel不支持");
break;
case 101:
case 102:
vscode.window.showWarningMessage("参数错误");
break;
case 103:
vscode.window.showWarningMessage(`当前不存在${pid}进程`);
break;
case 104:
vscode.window.showWarningMessage("当前进程未引用pthread动态库");
break;
default:
vscode.window.showWarningMessage("其他未知异常");
break;
}
return;
}
let pthreadlib = out.split('|');
if(pthreadlib.length < 2){
vscode.window.showWarningMessage(`${pid}进程检测程序无法识别`);
return;
}
let task = execDetect(passwd, pthreadlib[0], pid, (out2)=>{
if(out2.length ===0){
vscode.window.showWarningMessage(`未检测到进程${pid}相关锁信息`);
return;
}
if(out2.match(/fatal/)?.length){
vscode.window.showWarningMessage("被检测程序存在严重问题!");
}else if(out.match(/deadlock/)?.length){
}else if(out2.match(/deadlock/)?.length){
vscode.window.showWarningMessage("被检测程序存在死锁!");
}
if(out.match(/normal|fatal|deadlock/)?.length){
if(out2.match(/normal|fatal|deadlock/)?.length){
const webPanel = vscode.window.createWebviewPanel(
'detectResultWebview',
"检测结果",
@ -72,32 +101,14 @@ function localPidAnalyse(pid: number, passwd:string, context: vscode.ExtensionCo
retainContextWhenHidden: true,
}
);
webPanel.webview.html = prase_yaml2html(binPath, context.extensionPath, webPanel.webview, out);
webPanel.webview.html = prase_yaml2html(pthreadlib[1], context.extensionPath, webPanel.webview, out2);
}else{
vscode.window.showInformationMessage("未检测到相关锁信息");
}
return;
}
switch (code) {
case 100:
vscode.window.showInformationMessage("当前Kernel不支持");
break;
case 101:
vscode.window.showInformationMessage("未检测到相关锁信息");
break;
case 102:
vscode.window.showInformationMessage("未检测到相关锁信息");
break;
case 103:
vscode.window.showInformationMessage("未检测到相关锁信息");
break;
default:
vscode.window.showInformationMessage("未检测到相关锁信息");
break;
}
});
var pty = createTerm(pid, task);
var pty = createTerm(pid, passwd, task);
vscode.window.createTerminal({name:`检测进程 ${pid}`, pty}).show();
});
}
function remotePidAnalyse(pid: number, userAndhost: string, passwd: string) {
@ -135,7 +146,7 @@ export function DoLocalPidLockAnalyse(context: vscode.ExtensionContext) {
let pid = Number(data);
fs.access(`/proc/${pid}`, fs.constants.F_OK, (err)=>{
if(err){
vscode.window.showErrorMessage(`进程${pid}不存在`);
vscode.window.showErrorMessage(`进程${pid}不存在!`);
return;
}
vscode.window.showInputBox({

View File

@ -12,17 +12,18 @@ const archs = new Map([
const myArch = archs.get(process.arch);
const detectTool: string = join(dirname(__dirname), "detect-tools", myArch ? myArch: "x86_64", "deadlockcheck");
export function execDetect(pwd: string | undefined, libPthreadPath: string, checkedPid: number, cb: (da:string)=> void) {
export function execDetect(pwd: string | undefined, libPthreadPath: string, checkedPid: number, cb: (da:string)=> void):child.ChildProcess {
var task = child.exec(`echo ${pwd} | sudo -S ${detectTool} --threadlib ${libPthreadPath} --pid ${checkedPid}`, (err, out, e)=>{
if(err?.message){
vscode.window.showErrorMessage('附加到被检测程序失败, '+err.message);
return;
}
if(out.length){
// if(out.length){
cb(out);
}
// }
child.exec(`sudo -k`);
});
return task;
}
export function testPwd(pwd:string, cb: (ok: boolean)=>void): void {