【Chromium】Location信息内核调试

本文探讨了在Chromium浏览器内核开发过程中遇到的问题定位方法,特别是针对内核崩溃(Crash)的情况。通过深入分析Chromium的Looper机制,解释了如何利用Location信息来追踪导致崩溃的具体任务和回调,从而提高调试效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Chromium Location信息内核调试

  • 版本:Chromium80
  • 背景:基于Chromium进行浏览器内核开发的时候。有时候内核Crash,解析墓碑仅为PoskTask执行其对应的CallBack时崩溃。而定位问题,需要知道执行的具体任务是什么。
# base/callback.h
class OnceCallback<R(Args...)> : public internal::CallbackBase {
  // Run的时候Crash了。
  R Run(Args... args) && {
  	// 省略
  }
}
  • 首先,简单理解一下Chromium的Looper(这里已经按照个人的理解简易化)。
CallerExecutorLooperPostTaskScheduling Job?loop[ Healthcheck ]ALooper orlibeventRun TaskRun Call Back!If have callback.CallerExecutorLooper
  • 从上图,我们可以看出。再进行问题分析时(如解析墓碑),我们需要知道 Caller与Exccutor的信息。如何,知道两者的信息?使用Location便可以知道。
Location
  • 一般来讲PostTask时,将Location信息传给对应的接口。如
// FROM_HERE 为Location类型
PostTaskOnThread(FROM_HERE, content::BrowserThread::UI,
    base::Bind(&xxxx::func, ptr, args));
  • Location的定义如下:可以获得调用PostTask的函数名、行数、文件名等等。这样,我们便可以知道CallBack执行的Task的具体内容了。
// base/location.h

// Location provides basic info where of an object was constructed, or was
// significantly brought to life.
class BASE_EXPORT Location {
   // 省略
   // Will be nullptr for default initialized Location objects and when source
  // names are disabled.
  const char* function_name() const { return function_name_; }

  // Will be nullptr for default initialized Location objects and when source
  // names are disabled.
  const char* file_name() const { return file_name_; }

  // Will be -1 for default initialized Location objects and when source names
  // are disabled.
  int line_number() const { return line_number_; }

  // The address of the code generating this Location object. Should always be
  // valid except for default initialized Location objects, which will be
  // nullptr.
  const void* program_counter() const { return program_counter_; }

  // Converts to the most user-readable form possible. If function and filename
  // are not available, this will return "pc:<hex address>".
  std::string ToString() const;

}
  • 如果使用?例子如下
// xxx.cc
// 在Chromium源码中加入如下信息
// task->posted_from 为Location类型,此处假设在该文件中已经定义了这个对象。
LOG(INFO) << "HelpInfo:"<< task->posted_from.ToString();
  • 输出信息
[INFO:xxx.cc(99)] HelpInfo:Notify@../../../../../xxxx/chromium/src/mojo/public/cpp/bindings/lib/connector.cc:560
const largeObjectArray = this.createLargeObjectArray(); const newWatch = (callback) =>{ // table 打印时间 const tablePrintTime = this.calculateTime(() => { console.table(largeObjectArray); }); // 普通输出时间 const printLogTime = this.calculateTime(() => { console.log(largeObjectArray); }); // 有效时间检测(排除0值) if (tablePrintTime > 0 && printLogTime > 0) { // 动态阈值判断(当前值对比) if (tablePrintTime > printLogTime * 10) { console.log('时间对比新', tablePrintTime, printLogTime); callback(true); return; } } callback(false); }addListener(function(isOpen) { if (isOpen) { if ( document.body.innerHTML.indexOf('检测到非法调试,即将关闭此页面') < 0 ) { newWatch((isDetected) => { console.log('是什么', isDetected) if (isDetected) { document.body.innerHTML = '检测到非法调试,即将关闭此页面!'; alert('检测到非法调试,即将关闭此页面!'); window.location.href = 'about:blank'; if (window.history.replaceState) { window.history.replaceState( null, '', window.location.pathname + window.location.search, ); } } }); } } }); // 开始检测 launch(); // 禁用开发者工具 createLargeObject() { // 新 if (!this._largeObject) { this._largeObject = Array.from({length: 500}, (_, i) => ({ key: i, value: `${i}` }) ); } return this._largeObject; } // 创建大对象数组 createLargeObjectArray() { // 新 return Array(50).fill(this.createLargeObject()); } // 计算打印执行时间 calculateTime(func) { //新 const start = performance.now(); // 改用高精度时间 func(); return performance.now() - start; }以上代码在ie执行会报错么
最新发布
03-15
<think>嗯,用户问的是这段代码在IE浏览器里执行会不会报错。我需要仔细看看代码的结构和使用的特性,然后对照IE的支持情况。 首先,用户提供的代码中有箭头函数,比如`const newWatch = (callback) => {...}`和`addListener(function(isOpen) {...})`里面的箭头函数。IE不支持箭头函数,特别是IE11及更早版本根本不支持ES6的语法。所以这里肯定会报语法错误。 接下来是`console.table`方法,这个方法在IE中也是不支持的。IE的console对象只有基本的log、info、error等方法,没有table,所以调用`console.table`会导致错误,比如“对象不支持此属性或方法”。 然后是`performance.now()`,这个在IE10及以上是支持的,所以可能没问题。但需要确认用户提到的IE版本,如果是IE9或更早,这里也会有问题,但通常现在大部分IE用户可能是在IE11,所以这部分可能不会报错,但需要留意。 代码里还使用了`Array.from`和`Array.fill`。`Array.from`在IE中完全不支持,IE11也没有实现这个,所以当调用`createLargeObject`方法时,`Array.from({length:500}, ...)`会报错。同样,`Array.fill`在IE11中也是不支持的,所以`Array(50).fill(...)`也会导致错误。 另外,模板字符串`${i}`在IE中也不支持,这会导致语法错误。模板字符串是ES6的特性,IE无法解析,所以代码中的`value: `${i}``这部分会报错。 还有`const`声明变量。在ES6中,const是块级作用域,但IE11部分支持,不过在严格模式下可能没问题。不过如果代码没有使用严格模式,可能会有问题,但更主要的问题还是箭头函数和模板字符串等语法错误。 总结一下,代码中使用了多个ES6+的特性,这些在IE中都不支持,尤其是箭头函数、模板字符串、Array.from、Array.fill、console.table等。因此,当这段代码在IE中运行时,肯定会报多个语法错误,导致脚本无法执行。 可能的解决方案包括使用Babel等工具将代码转译到ES5,或者添加polyfill来弥补缺失的方法,比如Array.from和Array.fill的polyfill,同时替换掉console.table和箭头函数等语法。但考虑到IE的局限性,可能更实际的建议是放弃支持IE,或者提示用户使用现代浏览器。</think>以下是对该代码在IE浏览器兼容性的逐步分析: $\textcolor{blue}{主要兼容性问题}$: 1. $\textcolor{red}{箭头函数}$: - IE全系列不支持`() => {}`语法 - 影响范围:`newWatch`函数定义、回调函数参数 2. $\textcolor{red}{console.table()}$: - IE11及以下不支持此方法 - 会导致`TypeError`:执行到`console.table(largeObjectArray)`时会中断脚本 3. $\textcolor{red}{模板字符串}$: - `value: ${i}`语法在IE全系列不支持 - 会导致语法解析错误 4. $\textcolor{red}{Array方法}$: - `Array.from()`在IE全系列不支持(Edge12+支持) - `Array.fill()`在IE11及以下不支持 $\textcolor{blue}{次要兼容性问题}$: 1. $\textcolor{orange}{const声明}$: - IE10以下不支持块级作用域声明 - 但IE11部分支持(建议仍改为var) 2. $\textcolor{orange}{严格模式}$: - 代码未显式声明`'use strict'` - IE10+支持但行为可能不一致 $\textcolor{green}{可兼容部分}$: 1. $\textcolor{green}{performance.now()}$: - IE10+支持高精度时间测量 - 但IE9会报错 $\textcolor{blue}{错误触发流程}$: 1. 语法解析阶段就会因箭头函数报错 2. 如果使用转译工具处理了箭头函数: - 执行到`Array.from()`时触发`TypeError` 3. 如果修复了Array方法: - `console.table()`触发第二个运行时错误 $\textcolor{blue}{解决方案建议}$: 1. 使用Babel转译ES6+语法 2. 添加polyfill: ```javascript // Array.from polyfill if (!Array.from) { Array.from = function(...){...} } // console.table polyfill if (!console.table) { console.table = function(...){...} } ``` 3. 替换箭头函数为function声明 4. 改用字符串拼接代替模板字符串 $\textcolor{red}{结论}$: 该代码在IE全系列浏览器中均无法正常运行,会在不同执行阶段触发多个语法错误和运行时错误。建议最低需要Edge浏览器或现代Chromium内核浏览器才能正常运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值