地址超出范围

时间:2014-05-18 18:33:32

标签: c kernel

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-&gt;缓冲区中的字符串。它正确地复制了我检查过的缓冲区中的字符串。 cb-&gt;缓冲区的地址没有变化,但在崩溃时它显示的是不同的地址。


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

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


这是我的问题::

  1. 我永远不会改变这个缓冲区的地址。出于存储目的,我使用尾部偏移(如此*(cb->缓冲器+ cb->; tail_offset)= ch;并且像这样增加tail_offset cb-&gt; tail_offset =(++ cb-&gt; tail_offset) %cb->容量;

  2. 我对容量,head_offset和tail_offset的内容感到好奇。请看崩溃o / p。

  3. crash-- cir_debug_log cir_debug_log:$ 7:缓冲区 - 0xac3d83097f040056,容量 - 67131560, head_offset - 2303465086, tail_offset - 1156221409, vxl_lock - 000

1 个答案:

答案 0 :(得分:0)

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*.