银河麒麟服务器系统中mysql数据库使用gdb内存回收报错问题处理

银河麒麟服务器系统中mysql数据库使用gdb内存回收报错问题处理

    • [一 系统环境](#一 系统环境)
    • [二 问题现象](#二 问题现象)
    • [三 分析原因](#三 分析原因)
    • [四 解决方法](#四 解决方法)

问题描述:在系统中执行回收命令(gdb --batch --pid pidof mysqld --ex 'call malloc_trim(0)';)报错'malloc_trim' has unknown return type; cast the call to its declared return type

一 系统环境

bash 复制代码
[root@localhost ~]# nkvers 
############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Sword)

Kernel:
4.19.90-24.4.v2101.ky10.x86_64

Build:
Kylin Linux Advanced Server
release V10 (SP2) /(Sword)-x86_64-Build09/20210524
#################################################

二 问题现象

bash 复制代码
[root@localhost ~]# gdb --batch --pid `pidof mysqld` --ex 'call malloc_trim(0)';
[New LWP 2916]
[New LWP 2917]
[New LWP 2918]
[New LWP 2919]
[New LWP 2920]
[New LWP 2921]
[New LWP 2922]
[New LWP 2923]
[New LWP 2924]
[New LWP 2925]
[New LWP 2926]
[New LWP 2927]
[New LWP 2929]
[New LWP 2930]
[New LWP 2931]
[New LWP 2932]
[New LWP 2933]
[New LWP 2934]
[New LWP 2935]
[New LWP 2936]
[New LWP 2937]
[New LWP 2938]
[New LWP 2939]
[New LWP 2940]
[New LWP 2941]
[New LWP 2942]
[New LWP 2943]
[New LWP 2944]
[New LWP 2945]

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
0x00007fb2130629d9 in poll () from target:/usr/lib64/libc.so.6
'malloc_trim' has unknown return type; cast the call to its declared return type
[Inferior 1 (process 2914) detached]

三 分析原因

在C语言中,malloc_trim函数通常没有返回值,也就是说,它的返回类型是void。因此,malloc_trim函数不应该被强制转换为int类型。这样的转换在标准C语言中是没有意义的,因为malloc_trim不会返回一个整数值。

然而,一些特定的C库实现(如GNU C库)可能会为malloc_trim提供一个非标准的返回值,例如返回释放的内存字节数。在这种情况下,将malloc_trim的返回值强制转换为int可能是为了与这些非标准实现兼容。

总的来说,call (int)malloc_trim(0)call malloc_trim(0)在标准C语言中的行为应该是相同的,因为malloc_trim的标准定义不包含返回值。但是,如果您的代码依赖于某个特定C库的非标准扩展,那么这两种调用方式可能会有所不同:

  • call (int)malloc_trim(0):这种调用方式尝试将malloc_trim的任何返回值(如果有)强制转换为int类型。如果malloc_trim实际上返回了一个整数值,那么这个值将被转换为int类型。
  • call malloc_trim(0):这种调用方式忽略了malloc_trim的任何返回值。这是标准C语言中推荐的调用方式,因为它遵循了malloc_trim的标准定义。

需要将malloc_trim函数指定为int整数类型

四 解决方法

将gdb --batch --pid pidof mysqld --ex 'call malloc_trim(0)';命令修改为gdb --batch --pid pidof mysqld --ex 'call (int)malloc_trim(0)';

bash 复制代码
[root@localhost ~]# gdb --batch --pid `pidof mysqld` --ex 'call (int)malloc_trim(0)';
[New LWP 2916]
[New LWP 2917]
[New LWP 2918]
[New LWP 2919]
[New LWP 2920]
[New LWP 2921]
[New LWP 2922]
[New LWP 2923]
[New LWP 2924]
[New LWP 2925]
[New LWP 2926]
[New LWP 2927]
[New LWP 2929]
[New LWP 2930]
[New LWP 2931]
[New LWP 2932]
[New LWP 2933]
[New LWP 2934]
[New LWP 2935]
[New LWP 2936]
[New LWP 2937]
[New LWP 2938]
[New LWP 2939]
[New LWP 2940]
[New LWP 2941]
[New LWP 2942]
[New LWP 2943]
[New LWP 2944]
[New LWP 2945]

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.

warning: Expected absolute pathname for libpthread in the inferior, but got target:/usr/lib64/libpthread.so.0.

warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
0x00007fb2130629d9 in poll () from target:/usr/lib64/libc.so.6
$1 = 1
[Inferior 1 (process 2914) detached]
相关推荐
康熙38bdc几秒前
Linux 环境变量
linux·运维·服务器
存储服务专家StorageExpert16 分钟前
DELL SC compellent存储的四种访问方式
运维·服务器·存储维护·emc存储
容器( ु⁎ᴗ_ᴗ⁎)ु.。oO18 分钟前
MySQL事务
数据库·mysql
hakesashou1 小时前
python如何比较字符串
linux·开发语言·python
Ljubim.te1 小时前
Linux基于CentOS学习【进程状态】【进程优先级】【调度与切换】【进程挂起】【进程饥饿】
linux·学习·centos
cooldream20091 小时前
Linux性能调优技巧
linux
大G哥1 小时前
记一次K8S 环境应用nginx stable-alpine 解析内部域名失败排查思路
运维·nginx·云原生·容器·kubernetes
数据龙傲天1 小时前
1688商品API接口:电商数据自动化的新引擎
java·大数据·sql·mysql
长天一色1 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
醉颜凉2 小时前
银河麒麟桌面操作系统修改默认Shell为Bash
运维·服务器·开发语言·bash·kylin·国产化·银河麒麟操作系统