【问题标题】:Address out of bounds地址越界
【发布时间】:2014-05-18 18:33:31
【问题描述】:
crash --- cir_debug_log
cir_debug_log = $7 = {
buffer = 0xac3d83097f040056 <Address 0xac3d83097f040056 out of bounds>, 

crash --- print *cir_debug_log->buffer
Cannot access memory at address 0xac3d83097f040056
gdb: gdb request failed: print *cir_debug_log->buffer
crash ---

这里我定义了一个全局结构

typedef struct circular_buffer 

char            *buffer;
unsigned        capacity;
unsigned        head_offset;
unsigned        tail_offset;
volspin_t       vxl_lock;

extern struct circular_buffer cir_debug_log;

我正在初始化它的驱动程序加载时间,并在整个过程中跟踪它的地址,这个过程没有改变。

cb->buffer : mzalloc_sleep(25000* sizeof(char));

但不知何故,我无法通过 CRASH 打印 cir_debug_log->buffer 中存在的字符串。它正在正确复制我检查过的这个缓冲区中的字符串。 cb->buffer 的地址没有改变,但在崩溃时它显示不同的地址。


cb_push_data: end trying to print messgae with cb->buffer contains buffer_content=
"Purging msg accumulated during reonline operation "

这是我的字符串,也应该通过崩溃打印出来。


这是我的问题::

  1. 我从不更改此缓冲区的地址。出于存储目的,我使用尾部偏移量(像这样 *(cb->buffer + cb->tail_offset) = ch; 并像这样增加尾部偏移量 cb->tail_offset = (++cb->tail_offset)%cb->容量;

  2. 很好奇容量、head_offset和tail_offset的内容。请查看崩溃 o/p。

崩溃-- cir_debug_log cir_debug_log:$7:缓冲区——0xac3d83097f040056,容量——67131560, head_offset -- 2303465086, tail_offset -- 1156221409, vxl_lock -- 000

【问题讨论】:

  • 您能否澄清“cb->buffer 的地址没有改变但在崩溃中显示不同的地址”是什么意思?您的代码的某些部分(或 - 不太可能 - 内核中的某些其他驱动程序)可能正在破坏 cir_debug_log 并用垃圾覆盖 buffer 指针值。这个值(以 0x56 结尾)对于你 malloc 的内容看起来有点奇怪。
  • 这是我的问题 :: 1. 我从不更改此缓冲区的地址。出于存储目的,我使用尾部偏移量(像这样 *(cb->buffer + cb->tail_offset) = ch; 并像这样增加尾部偏移量 cb->tail_offset = (++cb->tail_offset)%cb-> capacity; 2.我很好奇容量,head_offset和tail_offset的内容,请看crash o/p. crash> cir_debug_log cir_debug_log = $7 = { buffer = 0xac3d83097f040056
    , capacity = 67131560, head_offset = 2303465086,tail_offset = 1156221409,vxl_lock = {}
  • 当然看起来该结构已被丢弃。鉴于您 malloc'ed 25,000 个字节,这些值没有意义。不幸的是,我没有任何关于内核驱动程序调试的技巧。
  • 感谢安德鲁的努力。

标签: c kernel


【解决方案1】:
I see you have this code displayed, which is missing most of the initialization 
and what is displayed contains some syntax errors

typedef struct circular_buffer 
{ // this line is missing
char            *buffer;
unsigned        capacity;
unsigned        head_offset;
unsigned        tail_offset;
volspin_t       vxl_lock;
} // this line is missing

extern struct circular_buffer cir_debug_log;


// where is this declaration of 'cb'?
struct circular_buffer *cb = cir_debug_log; 

// where is the initialization of the other fields?
cb->capacity = 25000 * sizeof(char);
cb->head_offset = 0;
cd->tail_offset = 0;

// this has a syntax error: ':' should be '='
cb->buffer : mzalloc_sleep(25000* sizeof(char)); 


BTW:
it is normal to write to the *head* and read from the *tail*.

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    相关资源
    最近更新 更多