Last active
August 29, 2024 08:18
-
-
Save chobits/b2db8d1aca8ebcc94637d91e28850957 to your computer and use it in GitHub Desktop.
nginx.gdb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: set ft=gdb | |
set print pretty on | |
set pagination off | |
set print repeats 16 | |
handle SIGPIPE nostop | |
### nginx debug function ### | |
# dump headers of HTTP request with pointer of (ngx_http_request_t *) r | |
# (gdb) dump_headers <pointer of (ngx_http_request_t *) r> | |
define dump_headers | |
set $r = $arg0 | |
set $i = 0 | |
set $part = &$r->headers_in.headers.part | |
set $header = (ngx_table_elt_t *) $part->elts | |
while 1 | |
if $i >= $part->nelts | |
if $part->next == 0x0 | |
printf "next\n" | |
loop_break | |
end | |
set $part = $part->next | |
set $header = (ngx_table_elt_t *) $part->elts | |
set $i = 0 | |
end | |
printf "%d: ", $i | |
#print $header[$i] | |
printf "%s: %s\n", $header[$i].key.data, $header[$i].value.data | |
set $i = $i + 1 | |
end | |
end | |
define dump_resp_headers | |
set $r = $arg0 | |
set $i = 0 | |
set $part = &$r->headers_out.headers.part | |
set $header = (ngx_table_elt_t *) $part->elts | |
while 1 | |
if $i >= $part->nelts | |
if $part->next == 0x0 | |
printf "next\n" | |
loop_break | |
end | |
set $part = $part->next | |
set $header = (ngx_table_elt_t *) $part->elts | |
set $i = 0 | |
end | |
printf "%d: ", $i | |
#print $header[$i] | |
printf "%s: %s\n", $header[$i].key.data, $header[$i].value.data | |
set $i = $i + 1 | |
end | |
end | |
define dump_br_headers | |
set $r = $arg0 | |
set $i = 0 | |
set $part = &$r->send_headers.part | |
set $header = (ngx_table_elt_t *) $part->elts | |
while 1 | |
if $i >= $part->nelts | |
if $part->next == 0x0 | |
printf "next\n" | |
loop_break | |
end | |
set $part = $part->next | |
set $header = (ngx_table_elt_t *) $part->elts | |
set $i = 0 | |
end | |
printf "%d: ", $i | |
#print $header[$i] | |
printf "%s: %s\n", $header[$i].key.data, $header[$i].value.data | |
set $i = $i + 1 | |
end | |
end | |
# dump connections of ngx_cycle->connections[0 ~ (<connections number> - 1)] | |
# (gdb) dump_connection <connecitons number> | |
define dump_connection | |
set $i = $arg0 | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
printf "connection[%d]: %p\n", $i, $c | |
# for reqstatus patch | |
#printf "received: " | |
#p $c->received | |
printf "data:%p fd:%d sent:%lld requests:%d\n", $c->data, $c->fd, $c->sent, $c->requests | |
if $c->log && $c->log->action | |
printf "action: %s\n", $c->log->action | |
end | |
if $c->read | |
printf "read timedout:%d, handler: ", $c->read->timedout | |
p $c->read->handler | |
end | |
if $c->write | |
printf "write timedout:%d, handler: ", $c->write->timedout | |
p $c->write->handler | |
end | |
ngx_poolsize $c->pool | |
printf "\n" | |
end | |
# dump unclosed connection in ngx_cycle->connections[0 ~ (<connetions number> - 1)] | |
# (gdb) dumpic <connecitons number> | |
define dumpic | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 | |
dump_connection $i | |
end | |
set $i = $i + 1 | |
end | |
end | |
define dump_rtmp_connection | |
set $i = $arg0 | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
set $s = (ngx_rtmp_session_t *) $c->data | |
printf "connection[%d]: %p rtmp_session: %p\n", $i, $c, $s | |
printf "data:%p fd:%d sent:%lld requests:%d\n", $c->data, $c->fd, $c->sent, $c->requests | |
printf "flashver: " | |
p $s->params.flashver | |
if $c->log && $c->log->action | |
printf "action: %s\n", $c->log->action | |
end | |
printf "\n" | |
end | |
# dump rtmp connection in ngx_cycle->connections[0 ~ (<connetions number> - 1)] | |
# (gdb) dumpc_rtmp <connecitons number> | |
define dumpc_rtmp | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->data != 0 | |
set $s = (ngx_rtmp_session_t *) $c->data | |
if $s->connection == $c | |
dump_rtmp_connection $i | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump processing streams in spdy connection | |
# (gdb) dump_streams <pointer of (ngx_http_spdy_connection_t *) sc> | |
define dump_streams | |
set $sc = $arg0 | |
set $stream = $sc->streams_index[32] | |
set $i = 0 | |
set $index = 0 | |
while $i < 32 | |
set $stream = $sc->streams_index[$i] | |
while $stream != 0x0 | |
printf "%4d: ", $index | |
p $stream | |
set $index = $index + 1 | |
if $stream->request->upstream.peer.connection | |
printf "upstream connection fd: %d\n", $stream->request->upstream.peer.connection->fd | |
printf "fc.read.eof:%d fc.write.eof:%d\n", $stream->request->connection.read.eof, $stream->request->connection.write.eof | |
printf "fc.write.handler: " | |
p $stream->request->connection.write.handler | |
printf "r->write_event_handler: " | |
p $stream->request->write_event_handler | |
end | |
set $stream = $stream->index | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump dangling connection of writing request in ngx_cycle->connections[0 ~ (<connections numbers>-1)] | |
# (gdb) dumpic_wr <connecitons number> | |
define dumpic_wr | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->data != 0x0 | |
set $r = (ngx_http_request_t *)$c->data | |
#if $r->connection == $c && $r->stat_writing != 0 && $c->write->timer_set == 0 && $c->read->timer_set == 0 | |
if $r->connection == $c && $r->stat_writing != 0 | |
printf "------\n" | |
dump_connection $i | |
printf "%.*s%.*s" $r->headers_in .host.value.len, $r->headers_in .host.value.data, $r->uri.len, $r->uri.data | |
printf "status: %d content-length: %d\n", $r->headers_out.status, $r->headers_out.content_length_n | |
p $r->read_event_handler | |
p $r->write_event_handler | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump dangling connection of writing request in ngx_cycle->connections[0 ~ (<connections numbers>-1)] | |
# (gdb) dumpic_pool_r <connecitons number> | |
define dumpic_pool_r | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->data != 0x0 | |
set $r = (ngx_http_request_t *)$c->data | |
if $r->connection == $c | |
printf "------\n" | |
dump_connection $i | |
p $r->uri | |
printf "status: %d content-length: %d\n", $r->headers_out.status, $r->headers_out.content_length_n | |
p $r->read_event_handler | |
p $r->write_event_handler | |
poolsize $r->pool | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump upstream c->pool | |
# (gdb) dump_ups <connecitons number> | |
define dump_ups | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->data != 0x0 | |
set $r = (ngx_http_request_t *)$c->data | |
if $r->connection == $c | |
if $r->upstream.peer.connection | |
printf "------\n" | |
dump_connection $i | |
p $r->uri | |
p *$r->headers_in.host | |
printf "status: %d content-length: %d\n", $r->headers_out.status, $r->headers_out.content_length_n | |
poolsize $r->upstream.peer.connection.pool | |
end | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump dangling spdy connection in ngx_cycle->connections[0 ~ (<connections number> - 1)] | |
# (gdb) dumpic_spdy <connecitons number> | |
define dumpic_spdy | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->data != 0x0 && $c->error | |
set $sc = (ngx_http_spdy_connection_t *) $c->data | |
#if $r->connection == $c && $r->stat_writing != 0 && $c->write->timer_set == 0 && $c->read->timer_set == 0 | |
if $sc->connection == $c | |
printf "processing: %d\n", $sc->processing | |
dump_connection $i | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump timers that are not freed | |
define dump_timer | |
dump_timer_iter ngx_event_timer_rbtree.root | |
end | |
define dump_timer_iter | |
# NOTE: dont set $node = $arg0, because $node will be changed by next calling dump_timer_iter() | |
if $arg0 != ngx_event_timer_rbtree.sentinel | |
# timer node($arg0) to event($ev) | |
set $ev = (ngx_event_t *) ((char *) $arg0 - (int)&((ngx_event_t *) 0x0)->timer) | |
printf "set $ev = (ngx_event_t *) %p\n", $ev | |
p *$ev | |
printf "\n" | |
dump_timer_iter $arg0->left | |
dump_timer_iter $arg0->right | |
end | |
end | |
# dump resoler nodes in r->name_rbtree | |
define dump_rn | |
set $_root = $arg0->name_rbtree.root | |
set $_sentinel = $arg0->name_rbtree.sentinel | |
dump_rn_iter $_root $_sentinel | |
end | |
define dump_rn_iter | |
if $arg0 != $arg1 | |
set $rn = (ngx_resolver_node_t *) $arg0 | |
print $rn | |
print $rn->name | |
dump_rn_iter $arg0->left $arg1 | |
dump_rn_iter $arg0->right $arg1 | |
end | |
end | |
# save connection pointer into $c with specific fd | |
# (gdb) fd2c <fd> | |
define fd2c | |
set $fd = $arg0 | |
set $i = 0 | |
set $n = ngx_cycle->connection_n | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd == $fd | |
printf "found connections[%d] = %p\n", $i, $c | |
loop_break | |
end | |
set $i = $i + 1 | |
end | |
end | |
# print address and port of sockaddr | |
# (gdb) psock <pointer of (struct sockaddr *) sockaddr> | |
define psock | |
set $_s = (struct sockaddr_in *) $arg0 | |
# port: ntohs($_s.sin_port) | |
set $_port = (($_s.sin_port & 0xff00) >> 8) + (($_s.sin_port & 0xff) << 8) | |
# ipv4 address: | |
set $_a = ($_s.sin_addr.s_addr & 0x000000ff) | |
set $_b = ($_s.sin_addr.s_addr & 0x0000ff00) >> 8 | |
set $_c = ($_s.sin_addr.s_addr & 0x00ff0000) >> 16 | |
set $_d = ($_s.sin_addr.s_addr & 0xff000000) >> 24 | |
printf "%d.%d.%d.%d:%d\n", $_a, $_b, $_c, $_d, $_port | |
end | |
# r2clcf(r) | |
# request to http loc conf | |
define r2clcf | |
set $clcf = (ngx_http_core_loc_conf_t *) $arg0->loc_conf[ngx_http_core_module.ctx_index] | |
end | |
# poolsize(pool) | |
define poolsize | |
set $_p = (ngx_pool_t *) $arg0 | |
set $_s = $_p->size | |
set $_l = $_p->large | |
set $_i = 0 | |
set $_max_large_sz = 0 | |
while $_l != 0x0 | |
if $_l->size > $_max_large_sz | |
set $_max_large_sz = $_l->size | |
end | |
set $_s = $_s + $_l->size | |
set $_l = $_l->next | |
set $_i = $_i + 1 | |
if $_i == 1000 | |
printf "pool large loop??\n" | |
set $_l = 0x0 | |
end | |
end | |
printf "pool size = %u (%d), nlarge = %d, max_large_sz = %d\n", $_s, $_p->size, $_i, $_max_large_sz | |
end | |
# poolsizex(pool) | |
define poolsizex | |
set $_p = (ngx_pool_t *) $arg0 | |
set $_s = $_p->size | |
set $_l = $_p->large | |
set $_i = 0 | |
set $_max_large_sz = 0 | |
while $_l != 0x0 | |
if $_l->size > $_max_large_sz | |
set $_max_large_sz = $_l->size | |
end | |
set $_s = $_s + $_l->size | |
set $_l = $_l->next | |
set $_i = $_i + 1 | |
end | |
printf "pool size = %u (%d), nlarge = %d, max_large_sz = %d\n", $_s, $_p->size, $_i, $_max_large_sz | |
end | |
# dumpic_pool(n) | |
define dumpic_pool | |
set $i = 0 | |
set $n = $arg0 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 | |
if $c->pool != 0x0 | |
printf "connection[%d]: ", $i | |
poolsize $c->pool | |
end | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dumpic_pool_stat(n, pool_stat) | |
define dumpic_pool_stat | |
set $i = 0 | |
set $n = $arg0 | |
set $_stat = $arg1 | |
if $n > ngx_cycle->connection_n | |
set $n = ngx_cycle->connection_n | |
end | |
while $i < $n | |
if $i % 100 == 0 | |
printf ">>> scanning no.%d\n", $i | |
end | |
set $c = (ngx_connection_t *) &ngx_cycle->connections[$i] | |
if $c != 0 && $c->fd > 0 && $c->pool != 0x0 && $c->pool.stat == $_stat | |
printf "connection[%d]: ", $i | |
poolsize $c->pool | |
end | |
set $i = $i + 1 | |
end | |
end | |
# dump_chain(cl) | |
# cl -> ngx_chain_t * | |
define dump_chain | |
set $_cl = $arg0 | |
set $_i = 0 | |
while $_cl != 0x0 | |
set $_buf = $_cl->buf | |
printf "%3d cl:%p b:%p tag:%p pos-start=%d last-pos=%d\n", $_i, $_cl, $_buf, $_buf.tag, $_buf->pos - $_buf->start, $_buf->last - $_buf->pos | |
set $_cl = $_cl->next | |
set $_i = $_i + 1 | |
end | |
end | |
define dump_queue | |
set $_h = $arg0 | |
set $_q = $_h.next | |
set $_i = 0 | |
while $_q != $_h | |
print "[%3d] %p\n" , $_i, $_q | |
set $_q = $_q->next | |
set $_i = $_i + 1 | |
end | |
end | |
define q2stream | |
set $stream = (ngx_http_spdy_stream_t *) ((char*) $arg0 - (char*) &((ngx_http_spdy_stream_t *) 0)->queue) | |
end | |
# save (ngx_connection_t *) pointer into gdb variable $c | |
# (gdb) set_c <connection index in ngx_cycle->connections> | |
define set_c | |
set $c = &ngx_cycle->connections[$arg0] | |
end | |
# save (ngx_http_spdy_connection_t *) pointer into $sc | |
# (gdb) set_sc <connection index in ngx_cycle->connections> | |
define set_sc | |
set_c $arg0 | |
set $sc = (ngx_http_spdy_connection_t *) $c->data | |
end | |
# save (ngx_http_request_t *) pointer into $r | |
# (gdb) set_r <connection index in ngx_cycle->connections> | |
define set_r | |
set_c $arg0 | |
set $r = (ngx_http_request_t *) $c->data | |
end | |
# dump in-used nginx pool (ngx_pool_t) | |
# NOTE: nginx should be compiled with NGX_DEBUG_POOL(mod_debug_pool) macro. | |
define debug_pool | |
set $_i = 0 | |
set $_ss = 0 | |
set $_ns = 0 | |
set $_cs = 0 | |
set $_ls = 0 | |
while $_i < 997 | |
set $_ps = ngx_pool_stats[$_i] | |
while $_ps != 0x0 | |
printf "size:%12u num:%12d cnum:%12d lnum:%12d %s:%d\n", \ | |
$_ps->size, $_ps->num, $_ps->cnum, $_ps->lnum, $_ps->func, $_i | |
set $_ss = $_ss + $_ps->size | |
set $_ns = $_ns + $_ps->num | |
set $_cs = $_cs + $_ps->cnum | |
set $_ls = $_ls + $_ps->lnum | |
set $_ps = $_ps->next | |
end | |
set $_i = $_i + 1 | |
end | |
printf "size:%12u num:%12d cnum:%12d lnum:%12d [SUMMARY]\n", $_ss, $_ns, $_cs, $_ls | |
end | |
## fast dump 1: $ gdb -p <pid> -ex 'set confirm off' -ex 'source gdbinit' -ex 'debug_pool' -ex 'quit' | |
## fast dump 2: $ gdb -q -p 12636 -x gdbinit2 ## (gdbinit2: define debug_pool + call debug_pool) | |
# dump symbol `rlcf->codes` in ngx_http_rewrite_handler | |
define dump_script_codes | |
set $_codes = (ngx_array_t *) $arg0 | |
set $_ip = $_codes->elts | |
while *(uintptr_t *)$_ip != 0x0 | |
set $_code = *(ngx_http_script_code_pt *) $_ip | |
printf "void: %p %p\n", (void*)$_code, ngx_http_script_copy_code | |
if $_code == ngx_http_script_copy_code | |
p *(ngx_http_script_copy_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_copy_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_copy_var_code | |
p *(ngx_http_script_var_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_var_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_set_var_code | |
p *(ngx_http_script_var_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_var_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_var_code | |
p *(ngx_http_script_var_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_var_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_copy_capture_code | |
p *(ngx_http_script_copy_capture_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_copy_capture_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_regex_end_code | |
p *(ngx_http_script_regex_end_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_regex_end_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_full_name_code | |
p *(ngx_http_script_full_name_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_full_name_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_return_code | |
p *(ngx_http_script_return_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_return_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_file_code | |
p *(ngx_http_script_file_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_file_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_if_code | |
p *(ngx_http_script_if_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_if_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_complex_value_code | |
p *(ngx_http_script_complex_value_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_complex_value_code_t) | |
loop_continue | |
end | |
if $_code == ngx_http_script_value_code | |
p *(ngx_http_script_value_code_t *) $_ip | |
set $_ip = (char *) $_ip + sizeof(ngx_http_script_value_code_t) | |
loop_continue | |
end | |
printf "ERROR: cannot found function for %p\n", $_code | |
printf "--- output for `disassemble %p`:\n", $_code | |
disassemble $_code | |
loop_break | |
end | |
end | |
# cscf r | |
define cscf | |
p (ngx_http_core_srv_conf_t *)($arg0->srv_conf[ngx_http_core_module.ctx_index]) | |
end | |
# server_name r | |
define server_name | |
p ((ngx_http_core_srv_conf_t *)($arg0->srv_conf[ngx_http_core_module.ctx_index])).server_name | |
end | |
### http2 ### | |
# h2scf(http2 session) | |
define h2scf | |
set $h2scf = (ngx_http_v2_srv_conf_t *)($arg0.http_connection.conf_ctx ->srv_conf [ngx_http_v2_module.ctx_index]) | |
end | |
# dump processing streams in spdy connection | |
# (gdb) dump_streams <pointer of (ngx_http_spdy_connection_t *) sc> | |
define dump_h2streams | |
set $sc = $arg0 | |
set $i = 0 | |
set $index = 0 | |
while $i < 32 | |
set $node = $sc->streams_index[$i] | |
set $i = $i + 1 | |
while $node != 0x0 | |
set $stream = $node->stream | |
set $node = $node->index | |
if $stream == 0x0 | |
loop_continue | |
end | |
printf "%4d: \n", $index | |
set $index = $index + 1 | |
p $stream | |
set $request = $stream->request | |
# client: requeset | |
printf "time: %d\n", $request->start_sec | |
printf "r->write_event_handler: " | |
p $request->write_event_handler | |
printf "r->read_event_handler: " | |
p $request->read_event_handler | |
printf "fc->read.handler: " | |
p $request->connection.read.handler | |
printf "fc->write.handler: " | |
p $request->connection.write.handler | |
printf "fc.read.eof:%d fc.write.eof:%d\n", $request->connection.read.eof, $request->connection.write.eof | |
# event | |
set $ev = $request->connection->read | |
printf "r->read active:%d ready:%d timer_set:%d\n", $ev->active, $ev->ready, $ev->timer_set | |
set $ev = $request->connection->write | |
printf "r->write active:%d writey:%d timer_set:%d\n", $ev->active, $ev->ready, $ev->timer_set | |
# window | |
printf "swnd:%d rwnd:%d\n", $stream->send_window, $stream->recv_window | |
# upstream | |
if $request->upstream.peer.connection | |
printf "upstream connection fd: %d\n", $request->upstream.peer.connection->fd | |
end | |
end | |
end | |
end | |
## lua/luajit | |
# --- gc total: | |
# p ((global_State *)L->glref.ptr32 )->gc.total / 1024/1024.0 | |
# --- lua ctx: | |
# p ((ngx_http_lua_ctx_t *)(r->ctx[ngx_http_lua_module.ctx_index])) | |
# p ((ngx_http_lua_ctx_t *)($r->ctx[ngx_http_lua_module.ctx_index])).entry_co_ctx.co # $42 = (lua_State *) 0x7fd8de443f58 | |
# python sys.path.append("/home/admin/tproxy/openresty-gdb-utils") | |
# source /home/admin/tproxy/openresty-gdb-utils/luajit21.py | |
# trivial script for checking upstream server | |
#p *((ngx_http_upstream_srv_conf_t **)((ngx_http_upstream_main_conf_t *)((ngx_http_conf_ctx_t *)ngx_cycle->conf_ctx[ngx_http_module.index])->main_conf[ngx_http_upstream_module.ctx_index])->upstreams.elts)[0] | |
#set variable $uscfp = ((ngx_http_upstream_srv_conf_t **)((ngx_http_upstream_main_conf_t *)((ngx_http_conf_ctx_t *)ngx_cycle->conf_ctx[ngx_http_module.index])->main_conf[ngx_http_upstream_module.ctx_index])->upstreams.elts) | |
#print *(ngx_http_upstream_check_srv_conf_t *)$uscfp[4368]->srv_conf[ngx_http_upstream_module.ctx_index] | |
#p *((ngx_http_upstream_srv_conf_t **)((ngx_http_upstream_main_conf_t *)((ngx_http_conf_ctx_t *)ngx_cycle->conf_ctx[ngx_http_module.index])->main_conf[ngx_http_upstream_module.ctx_index])->upstreams.elts)[0] | |
# | |
python sys.path.append("/home/admin/tengine/openresty-gdb-utils") | |
source /home/admin/tengine/openresty-gdb-utils/luajit21.py | |
# or luajit21.py if u are using luajit-2.1 | |
# ngx_poolsize(pool) | |
define ngx_poolsize | |
set $_p = (ngx_pool_t *) $arg0 | |
set $_debug = 0 | |
set $_s = 0 | |
if $argc == 2 | |
set $_debug = 1 | |
end | |
if $_p != 0 | |
set $_cp = $_p->current | |
p $_cp | |
# for small alloc | |
if $_debug | |
printf "small block size:\n" | |
end | |
while (1) | |
if $_debug | |
printf "+ small block: %d\n", (size_t)$_cp->d.end - (size_t)$_cp | |
end | |
set $_s += (size_t)$_cp->d.end - (size_t)$_cp | |
set $_cp = $_cp->d.next | |
if (ngx_pool_t *)$_cp == (ngx_pool_t *)0 | |
loop_break | |
end | |
end | |
if $_debug | |
printf "\nlarge block size:\n" | |
end | |
# for large alloc | |
set $_l = $_p->large | |
set $_ls = 0 | |
set $_i = 0 | |
while $_l != 0x0 | |
if $_debug | |
printf "+ large block: ~%d\n", $_p->max | |
end | |
set $_ls = $_ls + $_p->max | |
set $_l = $_l->next | |
set $_i = $_i + 1 | |
if $_i == 1000 | |
printf "pool large loop??\n" | |
set $_l = 0x0 | |
end | |
end | |
if $_debug | |
printf "\n" | |
end | |
printf "pool size ~%u = large ~%d + small %d\n", $_s + $_ls, $_ls, $_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment